...

View Full Version : Info About Previous Month



tomyknoker
04-02-2007, 04:05 PM
I'm setting up a page that will tell me each month what members have logged in... But I want to run it on the 1st of the month and view the previous months results, at the moment I have only been able to work out how to get it to run for the current month... Any ideas?



$year = date('Y');
$month = date('m');

$results = mysql_query("SELECT * FROM `table` WHERE `loginDateTime` LIKE '%$month%'");

if (mysql_num_rows($results) < 1) {
die('There are no members who have logged in this month');
}

else {

while ($qry = mysql_fetch_array($results)) {
if (strtotime($qry['loginDateTime']) <= (time() + 86400*31)) {
$login .= 'Name: '.$qry["FirstName"].' '.$qry["LastName"].' ('.$qry["DateOfBirth"].') '.$qry["Email"].'\r\n';
}
}

while ($qry = mysql_fetch_array($results)) {
if (strtotime($qry['loginDateTime']) <= (time() + 86400*31)) {
$login .= 'Name: '.$qry["FirstName"].' '.$qry["LastName"].' ('.date("d-m-Y", strtotime($qry["DateOfBirth"])).') '.$qry["Email"].'';
}
}

devinemke
04-02-2007, 04:25 PM
$last_month = date('Y-m', strtotime('last month'));
$result = mysql_query("SELECT * FROM table WHERE CONCAT(YEAR(loginDateTime), '-', MONTH(loginDateTime)) = '$last_month'") or exit(mysql_error());

tomyknoker
04-02-2007, 04:30 PM
I received this error any ideas?



Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in e:\emailMembersLogin.php on line 18
There are no members who have logged in this monthPHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in e:\emailMembersLogin.php on line 18

devinemke
04-02-2007, 04:36 PM
what does mysql_error (http://www.php.net/mysql_error) have to say about your query?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum