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
https://forums.phpfreaks.com/topic/219815-delete-from-custom-order-list-problem/
Share on other sites

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.