Page 1 of 1

Selecting by dates

Posted: Wed Mar 29, 2006 5:53 am
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

Posted: Wed Mar 29, 2006 5:55 am
by onion2k
What's the error?

Posted: Wed Mar 29, 2006 5:56 am
by hame22
You have an error in your SQL syntax near 'where MONTH(last_login) = 0' at line 1

Posted: Wed Mar 29, 2006 7:18 am
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' ?

Posted: Wed Mar 29, 2006 7:21 am
by onion2k
Where's your FROM clause? Which table are you SELECTing from?

EDIT: Gah.. beaten by Ed.