wlogeshwaran Posted April 15, 2011 Share Posted April 15, 2011 This piece of code deletes the row having time less than system time. 1) $tim=time(); $timer=time()+100; 2) mysql_query("delete from test where time < $tim "); 3) mysql_query("update test set time=$timer where status='Waiting'); I want to execute line 3 , only when line 2 actually deletes a row in the table. Suggest me an idea or tell me what i have to do to check whether line 2 has actually deleted the row. Tell me the return value of the sql query once it get executed. Quote Link to comment https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/ Share on other sites More sharing options...
analog Posted April 15, 2011 Share Posted April 15, 2011 You can use mysql_affected_rows after 2 to check the number of rows it affected (deleted). Quote Link to comment https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/#findComment-1201992 Share on other sites More sharing options...
Muddy_Funster Posted April 15, 2011 Share Posted April 15, 2011 You could also tryusing an if : $tim=time(); $timer=time()+100; $del = mysql_query("delete from test where time < $tim "); $act = mysql_num_rows($del); if ($act != 0 ){mysql_query("update test set time=$timer where status='Waiting');} Not something I have tested, but should work I think. Quote Link to comment https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/#findComment-1202019 Share on other sites More sharing options...
mikosiko Posted April 15, 2011 Share Posted April 15, 2011 @Muddy.. read again http://php.net/manual/en/function.mysql-num-rows.php mysql_affected_rows is the correct way to do it as @analog said Quote Link to comment https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/#findComment-1202031 Share on other sites More sharing options...
PFMaBiSmAd Posted April 15, 2011 Share Posted April 15, 2011 You would also need to check if mysql_affected_rows returned a number greater-than zero because it will return a -1 when the query itself failed due to an error and a != 0 comparison would match a -1 Quote Link to comment https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/#findComment-1202039 Share on other sites More sharing options...
Muddy_Funster Posted April 15, 2011 Share Posted April 15, 2011 You would also need to check if mysql_affected_rows returned a number greater-than zero because it will return a -1 when the query itself failed due to an error and a != 0 comparison would match a -1 I never knew that, I thought that it was a 0/1 bit flag. Thanks for that PFM. Oh, and miko - I missed you Quote Link to comment https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/#findComment-1202044 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.