Click to See Complete Forum and Search --> : Info About Previous Month


tomyknoker
04-02-2007, 09:05 AM
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"].'';
}
}

metrostars
04-02-2007, 09:24 AM
IF that works you should be able to just do that again but replacing $month = date('m')

with

$month = date('m', mktime(0, 0, 0, date('m') - 1, 0, date('Y'));

tomyknoker
04-02-2007, 09:26 AM
Why shouldn't it work? Does it look wrong... I'm pretty new to php so any advice would be appreciated...

metrostars
04-02-2007, 10:00 AM
No,

It's just that I havent looked through it myself. I'm just saying that if that works OK , a simple modificaton would make the second work as well. I didn't test or look through the script thats all.