phpretard Posted October 22, 2008 Share Posted October 22, 2008 I am trying to delete about 10K rows. The script works without the form. With the from I get the error: Warning: mysql_query() [function.mysql-query]: Unable to save result set in ... on line 20 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ... on line 24 if (isset($_POST['deleterows'])){ include ("../connect.php"); $GetId=$_POST['rowsNum']; $delete=$_POST['rowsNum']; echo $GetId; $result = mysql_query("SELECT * FROM URLS WHERE id<='$GetId'"); //<<<< LINE 20 if (!result){die(mysql_error());} while($row = mysql_fetch_array($result)) //<<<< LINE 24 { mysql_query("DELETE FROM URLS WHERE id<='$delete' "); } mysql_close($con); } // END IF else{ echo" <form action='' method='post'> <font face=arial>Delete All Rows And Lower Starting With:</font><br> <input type=text name='rowsNum' size='40' autocomplete=off> <input type=submit name='deleterows' value='Delete'> </form> "; } // END ELSE I can't seem to find the problem. Any help today? Quote Link to comment Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 I don't think you can use those operators on strings, try removing the single quotes around '$GetId' Quote Link to comment Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 I get the same error without the single quotes and using: $result = mysql_query("SELECT * FROM URLS WHERE id<='".$GetId."' "); if (!result){die(mysql_error());} while($row = mysql_fetch_array($result)) { mysql_query("DELETE FROM URLS WHERE id<='".$delete."' "); } Quote Link to comment Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 Also, result here should be $result if (!result){die(mysql_error());} Quote Link to comment Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 You don't need any SELECT statement of loop. <?php if (isset($_POST['deleterows'])) { include ("../connect.php"); $GetId = mysql_real_escape_string($_POST['rowsNum']); if (mysql_query("DELETE FROM URLS WHERE id <= $GetId")) { echo mysql_affected_rows() . " deleted\n"; } else { echo "Query failed " . mysql_error(); } mysql_close($con); } else { echo" <form action='' method='post'> <font face=arial>Delete All Rows And Lower Starting With:</font><br> <input type=text name='rowsNum' size='40' autocomplete=off> <input type=submit name='deleterows' value='Delete'> </form> "; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 Not really sure why you are selecting them all before you delete them, since you use the same number in both cases, why not just delete them? $sql = "DELETE FROM URLS WHERE id<=$GetId"; echo $sql; //verify $GetId is populated $result = mysql_query ($sql) or die ("Error in $sql" .mysql_error()); *Same idea as above Quote Link to comment Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 That code worked. Unfortionatly id deleted every ID all 1,677,523 of them Quote Link to comment Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 *Same idea as above And only 6 minutes later! Quote Link to comment Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 That code worked. Unfortionatly id deleted every ID all 1,677,523 of them It will have deleted what you asked it to. What number did you put in your form? Quote Link to comment Share on other sites More sharing options...
feidakila Posted October 22, 2008 Share Posted October 22, 2008 ops, removing my code, didn't see the thorpe answer Quote Link to comment Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 1715886 Quote Link to comment Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 1715886 is higher then 1677523 , so assuming all 1,677,523 of your records had incremnting ids, indeed that query would have removed all rows. Makes perfect sense. Quote Link to comment Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 Oh I know. My Bad Quote Link to comment Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 I'm a slow typer *Same idea as above And only 6 minutes later! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.