Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/
Share on other sites

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.

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  ;D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.