Good Afternoon,

I'm struggling with something that should be simple (where I have most trouble - simple things)

Basically what I'm trying to do is when someone places an order on hold, I want to leave it on hold indefinitely unless someone else wants to place the same items on hold, then I check to see if what is on hold has been there for over 15 minutes (time enough for them to make the payment). If it has been there over 15 minutes than I will release the hold on it and allow the other person to purchase it.

I am querying a database like this:

$current=(date('Y-m-d G:i:s'));
    $release_time="00:15:00";

$sql_r="SELECT order_id, mem_id, shares, placed_date, status FROM Zreserve_".$reserve." WHERE track_id='$reserve_rec' AND status <> 'R'";
$result_r=mysql_query($sql_r);
$request_r=mysql_fetch_array($result_r);

I get the results that I expect from that query.

Then I need to see if the value of the placed_date (datetime field) plus 15 minutes is < $current (basically set to now - above ...)

I have tried many variations on adding the 15 minutes and am coming up blank.

print"<br>release time is ".$release_time."<br>should release after ".($request_r[3]+$release_time);
//  always prints out the it should release after 2012

if ($request_r[3]+$release_time < $current){
    // do some stuff that never gets done
}

I know it is going to be simple and I will probably kick myself for even asking, but I need to get this script done, and I'm banging my head against the wall.

Thanks in advance for your assistance.

Douglas

Recommended Answers

All 3 Replies

Member Avatar for diafol

If you make the date format unix_timestamp, you can add 15 mins like this:

$placed =  (unix timestamp from db)
$end = $placed + 900;
if($end < time())echo "time out!";

Alternatively you can use INTERVAL in your mysql, using datetime format:

DELETE FROM table WHERE DATE_ADD(`placed_date`, INTERVAL '15' MINUTE) < NOW();
$holdDate = strtotime($request_r[3]);
if(strtotime('+ 30 minute', $holdDate) < time()){
    dostuff;
}
$holdDate = strtotime($request_r[3]);
if(strtotime('+ 30 minute', $holdDate) < time()){
    dostuff;
}

Thank You BOTH for your responses...

The strtotime actually worked very well, but couldn't make the first suggestion work at all... I had already tried that one, but decided to try a second time, but with no luck.

Anyway, strtotime accomplishes what I needed to do, so another issue Resolved...

Thanks again
Douglas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.