7 Days or Younger

Hi, I run an online game, but I’m still a beginner when it comes to PHP. I can manipulate some of it, but I certainly cannot code from scratch yet. So please understand that I do not know all the technical jargon.

Anyway, I am attempting to create a automated list which populates the newest players within my game. I am defining being a new player as being less than 7 days old. My database captures their create date upon registration within the ‘member’ table.

[php]$createdate = date(‘Y-m-d H:i:s’);[/php]

Quick “know-how” on the database. There are two essential tables for this code, these are ‘Member’ & ‘Game’. Member table stores account information for each account which here we’ll need the create date & login name. Game table stores the current rounds information for each account and here we’ll need to mach the login name from member to the same login name in game in order to retrieve the correct game name(as these change every round).

I have two variations of what I’ve attempted. Not sure which is closer haha!

[php]<?
$query=“select game_name from game,member where (game.login_name = member.login_name and if ((member.createdate - date(‘Y-m-d H:i:s’); <= strtotime(‘7 days’)) ) order by createdate”;
$result=mysql_query($query) or die (“can’t get result4”);
$nrows=mysql_numrows($result);
if ($nrows > 0 ){
while ($row=mysql_fetch_array($result,MYSQL_ASSOC)){
echo “

$row[game_name]
”;
}
}
?>[/php]

[php] <?
$now = date(‘Y-m-d H:i:s’);
$query=“select game_name from game,member where (game.login_name = member.login_name and if ((member.createdate - $now <=7 )) order by createdate”;
$result=mysql_query($query) or die (“can’t get result4”);
$nrows=mysql_numrows($result);
if ($nrows > 0 ){
while ($row=mysql_fetch_array($result,MYSQL_ASSOC)){
echo “

$row[game_name]
”;
}
}
?>[/php]

If anybody can point me in the correct direction and tell me what I’m doing wrong and what would be the correct way I’d really appreciate it! This is my first time attempting to calculate anything with dates in PHP. Thanks in advance!!

Is member.createdate, defined as a Date field or a varchar in the database?

It’s defined as ‘datetime’

Try This…

[php]$query=“select game_name from game,member where game.login_name = member.login_name and member.createdate >= DATE_SUB(order_date, INTERVAL 7 DAY) order by createdate”;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service