Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

PHP help please

Status
Not open for further replies.

Admin

Administrator
Staff member
Joined
Jun 14, 2004
Posts
11,137
Reaction score
929
Hi all,

I am trying to get records from a DB where the date in a field is todays date, or the next day's date:

Code:
`fieldname` > date_SUB(CURdate(), INTERVAL 2 DAY)
doesn't work.

Any help please?

Thanks

Admin
 
Is the format of the date field in the DB table DATETIME instead of DATE?

DATETIME = YYYY-MM-DD HH:MM:SS
DATE = YYYY-MM-DD

Because CURDATE() returns the date in the format YYYY-MM-DD, which means if the date field was DATETIME then it would not match (the hours, mins, secs throwing it off) .

If so, you can use DATE_FORMAT to change the value extracted from the DATETIME field. For example:

PHP:
SELECT * FROM table WHERE DATE_FORMAT( datetime_field, '%Y-%m-%d' ) = DATE_SUB( CURDATE(), INTERVAL 2 DAY )
 
Thanks for the suggestion.

The field type is "int(10)" and shows a string of numbers which I assume is a Unix format date string.

Admin
 
In that case could try:

HTML:
SELECT * FROM table WHERE FROM_UNIXTIME( fieldname, '%Y-%m-%d' ) > date_SUB( CURDATE(), INTERVAL 2 DAY )
 
Didn't work.. no errors but no effect on SELECT statement results either
 
SELECT fieldname, FROM_UNIXTIME( fieldname, '%Y-%m-%d' ), CURDATE(), DATE_SUB( CURDATE(), INTERVAL 2 DAY )
FROM table
LIMIT 5

Paste in the results of the above query here - might make it easier to spot something...
 
It just selects all the records instead of just the ones with 2 days difference from today's date.
 
admin sorted code anyway. =)
 
Last edited:
In the auctions i only want the "view bids" to show if the auction has bids, how do I do that?

I also want to link (join) to another table to get the number of bids...

thanks

Admin
 
hi admin,

you probably already know, but i think maybe,

IF bidcount row >= 1 {

show }

else {
"be the first to bid" (whatever)
}

i could give a better answer if i could see the code, table/feild names.

pm me if you want me to have a "proper bash" tomo.
 
hi admin,

you probably already know, but i think maybe,

IF bidcount row >= 1 {

show }

else {
"be the first to bid" (whatever)
}

i could give a better answer if i could see the code, table/feild names.

pm me if you want me to have a "proper bash" tomo.
I'm already using the IF and ELSE to alternate the row colours. How do I do both?
 
Hi admin,

Im dont know the names of your rows or excatly how you've done the if/elses for the row colours, but maybe something like this,



your IF (condition for row colour) {

your if code for row colour;

/* new if stament */ IF (yourbidcount.row >= 1) {

print ("<a href=\"linkToBidPage/\">view bids</a> ");

}



else {

print("be the first to bid");

}

}

your else {

your else code for the row colour

/* new if stament */ IF (yourbidcount.row >= 1) {

print ("<a href=\"linkToBidPage/\">view bids</a> ");

}



else {

print("be the first to bid");

}

}


}


Its a bit messy, but should work.
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

New Threads

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom