Jump to content

display records between two dates (for the month)


Strato

Recommended Posts

Ok first sorry for such a newbie question  ::)

 

I had a friend create a stats.php file for me to display stats from a mysql database. Now I want to modify the stats so that I can view stats per month. Right now I can view all players stats or all games. I want to be able to make a link "View Jan Stats" and have it display only stats for Jan. Then "View Feb Stats", etc.

 

Basically I want to reward the top players for each month.

 

I have attached the stats.php file and I think the dates info are stored here:

 

		"CREATE TABLE IF NOT EXISTS `seasons` (" +
		"`id` int(10) unsigned NOT NULL auto_increment," +
		"`name` text NOT NULL," +
		"`start_date` timestamp NOT NULL default '0000-00-00 00:00:00'," +
		"`end_date` timestamp NOT NULL default '0000-00-00 00:00:00'," +
		"PRIMARY KEY  (`id`)" +
	") ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;"

 

 

 

[attachment deleted by admin]

Easiest way, use GET data with the month number:year.

 

Example link:

<a href="yourscript.php?month=1:2009">January</a>

 

Then on the page check for the month.

if (isset($_GET['month'])) {
    list($month, $year) = explode(":", $_GET['month']);
    $month = ($_GET['month'] < 13 && $_GET['month'] > 0)?$_GET['month']:1;
    $month = ($month < 10)?"0$month":$month; // pad it with a 0
    $data = "$month-$year";
    $query = "SELECT * FROM `seasons` WHERE DATE_FORMAT(`end_date`, '%c-%Y') = '" .  $data . "'";
}

 

Should get you started.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.