Jump to content

PHP Shift rows up when deleted


JonnySnip3r

Recommended Posts

Hey guys hope someone can help. Im fairly new to PHP and i was wondering if someone can point me the right direction. I'm creating a website and i have gotten to the point where im listing my members and when i delete them by id it has this:

 

id    name  email etc...

 

1    John    [email protected]

2    Will    [email protected]

3    Carl    [email protected]

 

say i delete Carl 3 has gone but how do i shift rows down? here is my delete phpcode.

 

$id = $_POST['id'];

   

    $mysqli = new mysqli('localhost', 'name', 'pass', 'db')

        or die ("There was a problem connecting to your database!");

       

    $stmt = $mysqli->prepare('DELETE FROM users WHERE id=?');

    $stmt->bind_param('i', $id);

    $stmt->execute();

    $stmt->close();

 

Hope someone can help, Thanks!

Link to comment
https://forums.phpfreaks.com/topic/202451-php-shift-rows-up-when-deleted/
Share on other sites

so its normal for databases to have skipped values like 1, 2, 4, 8, 9, 10, 12 etc? But thanks for the reply dude!

 

Yes, the ID field's purpose is to uniquely identify the row and should never change.  It's very common for the autoincrement ID field to have all kinds of holes in it, just like your checkbook if you've ever voided a check.

 

If you want to present to the user an order, then you can have a separate column for that, or just generate those numbers as you build the table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.