me1000 Posted May 20, 2008 Share Posted May 20, 2008 ok, So The user will be able to remove an entry from the database, however once they do it needs to update the rest of the entries... for example, there is an 'ORDER' column in the DB if there are 3 entries in the DB the order column would be filled out like so, '1,2'3' respectivly. however If I wanted to remove the row WHERE ORDER=1 the database will have the values to '2,3' instead it needs to update all the values that are greater than 1 and subtract 1 from them, so after you delete the row the db would be updated so that it said '1,2' again. Here is the PART script I have written so far.. $inPageID = (is_numeric($_REQUEST['id'])) ? $_REQUEST['id'] : die('invalid id'); $query = "SELECT * FROM nav WHERE ASSO=$inPageID"; $result = mysql_query($query); $blah = mysql_fetch_array($result); $newnum = $blah['ORDER']; $query = "SELECT * FROM nav WHERE `ORDER` > $newnum"; $count = mysql_num_rows(mysql_query($query)); //echo $count; //echo $query; //die; if ($count > 0) { $result = mysql_query($query); while ($blah123 = mysql_fetch_array($result)){ $newnum2 = $blah123['ORDER'] - 1; $query = "UPDATE nav SET `ORDER`='$newnum2' WHERE `ID`='".$blah123['ID']."'"; $result = mysql_query($query); $message = ($result) ? "" : 'FAIL!'; echo $message; //echo $query; } } The error im getting is... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [path...] on line 69 line 69 is while ($blah123 = mysql_fetch_array($result)){ I believe it updates the first row after that, but then it fails when it tries to loop again. Can anyone help me? Thanks, Link to comment https://forums.phpfreaks.com/topic/106475-update-several-mysql-rows/ Share on other sites More sharing options...
nloding Posted May 20, 2008 Share Posted May 20, 2008 It means your query wasn't successful. You need to put in some debugging code What you should do is place ... or die('Query failed: ' . mysql_error()); ... after all your queries, fetch_array's, etc., when debugging. So your query becomes: $result = mysql_query($query) or die('Query failed: ' . mysql_error()); I don't know if your first query (just before while loop), or the second query (inside the loop) is what's failing. The above tip will help. Link to comment https://forums.phpfreaks.com/topic/106475-update-several-mysql-rows/#findComment-545752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.