rtchin Posted April 14, 2008 Share Posted April 14, 2008 Hi, i'm trying to resort after deleting and item. when i echo the nested sql statement it looks right, however, when i go back to the database, the sort is all wrong. what happens is it always sorts the first two records with 0.. should be, 0,1,2,3,etc. so may table is always id namesort 1 aaa0 2 bbb0 3 ccc2 $sql="DELETE FROM categories WHERE id = $_GET[id]"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } $result = mysql_query("SELECT * FROM categories order by sort"); while($row = mysql_fetch_array($result)) { mysql_query("update categories set sort = $rank where id = $row[id]"); $rank++; //echo $update; } Link to comment https://forums.phpfreaks.com/topic/101006-need-help-with-nested-queries/ Share on other sites More sharing options...
paul2463 Posted April 14, 2008 Share Posted April 14, 2008 where do you initiate $rank??? if it does not exist to start with then it will cause problems, put a $rank = 0; between the $result line and the while line Link to comment https://forums.phpfreaks.com/topic/101006-need-help-with-nested-queries/#findComment-516581 Share on other sites More sharing options...
rtchin Posted April 14, 2008 Author Share Posted April 14, 2008 sorry, should have sent the whole script, not just the block. i initialize $rank at the top of the script as $rank=0; Link to comment https://forums.phpfreaks.com/topic/101006-need-help-with-nested-queries/#findComment-516789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.