/    Sign up×
Community /Pin to ProfileBookmark

Info About Previous Month

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?

[code=php]
$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”].’rn’;
}
}

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”].”;
}
}[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@metrostarsApr 02.2007 — 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'));
Copy linkTweet thisAlerts:
@tomyknokerauthorApr 02.2007 — Why shouldn't it work? Does it look wrong... I'm pretty new to php so any advice would be appreciated...
Copy linkTweet thisAlerts:
@metrostarsApr 02.2007 — 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.
×

Success!

Help @tomyknoker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...