auction script problem..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

auction script problem..

Post 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 :)
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post 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...
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post 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?
Post Reply