Reorder the id of a table [PHP & Mysqli]

0

Hello, I'm in a project where the order of the id's is quite important for the final result, but when I remove a line from the table, there's an empty id left over ... Ex:

IfIdeleteid2itwilllooklikethis...

IwantthecodeafterdeletingittochangeallIDs...Ihaveremovedtheself-incrementsothatIcanmodifybutnotwithmycodewhere$mate=table_name;

<?phpinclude"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 the deletion of the line without changing the id's of the others.

What do I do?

    
asked by anonymous 15.11.2017 / 23:45

1 answer

0

This does not make any sense. ids are a unique identifier in the ecosystem and are neither interchangeable nor should be. If the Goytai has the ID 1 and I the ID 2, if you die of natural causes you can not give your ID to another person since that ID is the number that identifies the SI and SO A SI in life or death. / p>     

16.11.2017 / 02:27