Jump to content

Delete from custom order list problem


pockitz

Recommended Posts

Hello all,

 

I have used the phpfreaks custom order list script to create, well, a custom order list, but for some reason the Delete section of the code is not reassigning the numbers correctly after an item is deleted. It deletes the record okay, but if I have:

 

1

2

3

4

and delete 3, then 4 should become 3

but 4 stays as 4 until it moves two places and then it becomes 3.

I am sure its related to part of this code, but please let me know if you have any ideas.

 

Cheers

Pockitz

 

// delete row from table
   $sql = "DELETE FROM images WHERE imgsequenceid = '$seqid'";
   $result = mysql_query($sql) or die(mysql_error());
   
   if($result){
		echo "Image $seqid successfully deleted from $id";
		}else{
		echo "ERROR";
		}


// select the info, ordering by sequenceid
   $sql = "SELECT imgsequenceid, imgid FROM images ORDER BY imgsequenceid";
   $result = mysql_query($sql) or die(mysql_error());
   // initialize a counter for rewriting sequenceid
   $seqid = 1;
   // while there is info to be fetched...
   while ($r = mysql_fetch_assoc($result)) {
      $imgid = $r['imgid'];
      // update the sequenceid number to the one in the next number
      $sql = "UPDATE images SET imgsequenceid = '$seqid' WHERE imgid = '$imgid'";
      $update = mysql_query($sql) or die(mysql_error());
      // inc to next avail number
      $seqid++;
   } // end while
} // end if del  

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.