Jump to content

new with questions about subdate.


makaiser

Recommended Posts

OK, new to this forum, struggling with something here.  All I'm after is a simple php/mysql script that checks to make sure something isn't stuck in the queue, and if there is something stuck, to send a mail off.  Currently what I've started with.

 

$query = "SELECT orderid FROM store_soap_queue WHERE done != 1 AND started >= SUBDATE(NOW(), INTERVAL 10 MINUTE)";

$results = @mysql_query($query);

if($results){

$orderid = array();

while($row = @mysql_fetch_array($results)){

$orderid[] = $row['orderid'];

}

 

$notify = print "The order ID that didn't go thru: $orderid at [".date('Y-m-d h:i:sa')."]";

 

$mailaddress = "[email protected]";

$mailsubject = "Stuff still in queue";

$mailbody = $notify;

 

mail($mailaddress,$mailsubject,$mailbody);

}

 

I know I'm probably messing something up with the subdate() function.  But I could be off, and am not the brightest star in the sky when it comes to mysql/php.

Link to comment
https://forums.phpfreaks.com/topic/61731-new-with-questions-about-subdate/
Share on other sites

You could use "NOW() - INTERVAL 10 MINUTE" alone instead of SUBDATE().  Do you mean "less than or equal to" instead of greater than/equal to?

 

Check for errors returning from the mysql_query call instead of hiding them; try "mysql_query(...) or die mysql_error();" for quick debugging.

I think I'm making this to difficult, I really don't need to know which items didn't make it through, rather just that something is stuck.

 

$query = "SELECT * FROM store_soap_queue WHERE done != 1 AND started <= NOW(),- INTERVAL 10 MINUTE";

$results = @mysql_query($query);

if($results){

 

$notify = print "An order didn't go through";

 

$mailaddress = "[email protected]";

$mailsubject = "Unfinished business in queue!";

$mailbody = $notify;

 

mail($mailaddress,$mailsubject,$mailbody);

}

else{

print "Nothing stuck in queue \n";

}

 

what do you think?

your original query was fine, your operator was wrong.  you need to select those whose date is LESS than or equal to 10 minutes ago - if it's greater than or equal to 10 minutes ago, it means it was started after ten minutes ago.  remember that a bigger date means more recent, whereas a smaller date means older:

 

SELECT orderid FROM store_soap_queue WHERE done != 1 AND started <= SUBDATE(NOW(), INTERVAL 10 MINUTE)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.