Page 1 of 1

auction script problem..

Posted: Tue Apr 18, 2006 6:40 pm
by The-Master
hi, i made a small auction script and i want that when the "real date and time" will equal to the expire date the auction will be over.

the table is like this:

Code: Select all

id, seller_id, seller_user, item_on_auction, item_auction_desc, item_starting_price, 
item_current_bid, bidder_id, bidder_user, expire_date, expire_time
EXPIRE_DATE AND ..._TIME ARE SET TO CHARSET!

thanks in advance :)

Posted: Tue Apr 18, 2006 7:11 pm
by hawleyjr
You need to set the fields to a datetime field and then look at some of the mysql date functions...

http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html

Posted: Wed Apr 19, 2006 3:18 am
by Oren
hawleyjr wrote:You need to set the fields to a datetime field and then look at some of the mysql date functions...

http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
Not really, just store the timestamp of the expiration date in the database and then compare it with the currnt timestamp.
Use strtotime() to get the timestamp of a string like: '19 April 2006' and store it in your database.

When you want to compare between the current time to the expiration time simply pull the timestamp from the database and then compare it with what you get from time() - return the current timestamp.

Posted: Fri Apr 21, 2006 8:10 pm
by The-Master
well the big problem is when the expire date is over and the query wasnet made then the auction will not be over...
what i mean is that when ($date_now == $expire_date) the expire date has come... and the query isn't made - nobody entered the page to make the query so $expire_date has past and the changes were never executed...

Posted: Fri Apr 21, 2006 8:44 pm
by The-Master
i think i found a solution:

Code: Select all

/* 
the code here until the next comment is executed when an auction is made
for example if someone is selling his shoes the auction expire days is two days since
the date the auction was made 
*/
$today = date("Y-m-d");
$expire_days = time() + (2 * 24 * 60 * 60); // plus two days
$expire_date = date("Y-m-d", $expire_days); // this is sent to the DB
// when the expire date has come >>>
// expire date is pulled from the DB >>>
if($today == $expire_date) {
echo "auction is over!";
// some other things...
}
you think this will work?