Selecting by dates

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
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Selecting by dates

Post by hame22 »

Hi I have a field in my records thats holds the last login date of a user, its default is set up as 0000-00-00

what I want to do is query all my users records to find out how many people have logged in, i.e. do not have a value of 0000-00-00

Have tried the following query but am getting an error, any ideas??

Code: Select all

$result = mysql_query("Select count(*) AS number where MONTH(last_login) = '00'") or die(mysql_error());

thanks in advance
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

What's the error?
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Post by hame22 »

You have an error in your SQL syntax near 'where MONTH(last_login) = 0' at line 1
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

Post by ed209 »

why can't you

Code: Select all

$query = " SELECT count(`last_login`) AS number FROM your_table WHERE `last_login` <> '0000-00-00' ";
... maybe you forgot to add the 'FROM TABLE' ?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Where's your FROM clause? Which table are you SELECTing from?

EDIT: Gah.. beaten by Ed.
Post Reply