Stavros Posted June 1, 2012 Share Posted June 1, 2012 Hello I need some help here as I cant see where I'm going wrong with my code??? I have say 5 rows in a table and if I delete row 3, row 3 is deleted and rows 4 & 5 are now renamed to rows 3 & 4. make sense? BUT when I try to delete row 1 I end up with two row 2's. Any help appreciated... //Find the amount of LineItems and delete $CheckItemDelete=$_GET["LineItemDelete"]; //Find quote number and show frames to edit $result = mysql_query("SELECT * FROM Table WHERE ID='1'") or die(mysql_error()); ($row = mysql_fetch_array($result)); $QuoteCheck = ($row['QuoteCheck']); mysql_query("DELETE FROM Table WHERE LineItems='$CheckItemDelete' && QuoteNum='$QuoteCheck'"); mysql_query("DELETE FROM Table WHERE LineItems='$CheckItemDelete' && QuoteNum='$QuoteCheck'"); mysql_query("DELETE FROM Table WHERE LineItems='$CheckItemDelete' && QuoteNum='$QuoteCheck'"); $result3 = mysql_query("SELECT * FROM Table WHERE QuoteNum='$QuoteCheck' ORDER BY LineItems ASC") or die(mysql_error()); ($row3 = mysql_fetch_array($result3)); while($row3 = mysql_fetch_array($result3)) { if (($row3['LineItems']) > $CheckItemDelete){ $LineItemCountAdjust = ($row3['LineItems']) - 1; $LineItemCount = ($row3['LineItems']); rename("Folder/$QuoteCheck$LineItemCount.png", "Folder/$QuoteCheck$LineItemCountAdjust.png"); echo "$LineItemCountAdjust"; echo "$LineItemCount"; $result = mysql_query("UPDATE Table SET LineItems ='$LineItemCountAdjust' WHERE LineItems='$LineItemCount' && QuoteNum='$QuoteCheck'") or die(mysql_error()); } } $MyDir = "Folder/"; $MyExt = ".png"; unlink($MyDir.$QuoteCheck.$CheckItemDelete.$MyExt); Link to comment https://forums.phpfreaks.com/topic/263467-deleting-a-row-and-renaming-the-remaining-rows-boggle/ Share on other sites More sharing options...
requinix Posted June 1, 2012 Share Posted June 1, 2012 Have you considered a simple UPDATE table SET field = field - 1 WHERE field > value you just deleted Link to comment https://forums.phpfreaks.com/topic/263467-deleting-a-row-and-renaming-the-remaining-rows-boggle/#findComment-1350225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.