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    john@lol.com

2    Will    lol@lol.com

3    Carl    gog@lol.com

 

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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.