0
Hello, I’m in a project where the order of id’s is quite important for the final result, but when removed a row of table is left an empty id... Ex.:
If I delete id 2 it will look like this...
I wanted the code after I deleted it to change all the ID’s... I already removed the auto-increment to modify but n with you ta ai my code where $mate = table name_table;
<?php
include"default.php";
if (isset($_GET['mat']) && isset($_GET['id'])) {
$mat = $_GET['mat'];
$id = $_GET['id'];
include"../ligacao.php";
$query = mysqli_query($conexao, "SELECT * FROM ".$mate);
$linhas = mysqli_num_rows($query);
if ($linhas == $id) {
mysqli_query($conexao, "DELETE FROM ".$mate." WHERE id = '$id'");
} elseif ($id < $linhas) {
mysqli_query($conexao, "DELETE FROM ".$mate." WHERE id = '$id'");
$idn = 1;
while ($idn > $linhas) {
mysqli_query($conexao, "UPDATE ".$mate." SET id = '$idn'");
$idn ++;
}
}
} ?>
The result is just deleting the line without changing the id’s of the others.
What I do ?
This is crazy... I would have to update each line by changing the primary key... the primary key exists to be unique and not be changed. Explain what would be "important to the end result" that there is certainly another way to do what you need
– Rovann Linhalis
You can create another column in the table, for example, code, and change this value, but not the id. Or in the table do a
i++
in the loop and print in the first column– Costamilam