Jump to content

[SOLVED] Help: MySQL dont show older than today


clown[NOR]

Recommended Posts

hi... i'm working on a website for my fiance's dad... and he's a jazz musician, so I'm making a database for upcoming shows. so, what I wonder now, is there a way to show only upcoming shows, and just exclude the shows older than todays date? what I've got atm is:

 

<?php
function visGigs()
{
	c2db("gigs");

	$query = "SELECT * FROM gigs ORDER BY dato DESC";
	$result = mysql_query($query);

	if (!$result) { die("Could not run query from database"); }

	$dbRows = mysql_num_rows($result);
	if ($dbRows > 0) {
		echo '<table border="0" cellspacing="1" cellpadding="0" bgcolor="#000000" width="100%">
			    <tr>
					<td width="20%" bgcolor="#A1C2A7"><div align="center"><strong>Tid</strong></div></td>
					<td width="80%" bgcolor="#A1C2A7"><div align="center"><strong>Sted</strong></div></td>
				</tr>
		';
		while ($dbField = mysql_fetch_assoc($result)) {
			$dnt = explode(" ", $dbField['dato']);

			echo '<tr><td width="20%" bgcolor="#A1C2A7" valign="top">'.formatDate($dnt[0]).'</td>
				  <td width="80%" bgcolor="#A1C2A7" valign="top"><a href="?vis=gigs&id='.$dbField['id'].'">'.$dbField['sted'].'</a></td></tr>';
		}
		echo '</table>';
	} else { echo "Fant ingen kommende spillejobber."; }
}
?>

 

Thanks In Advance

- Clown

Simplest would be to only retrieve database records that were for future dates:

 

$query = "SELECT * FROM gigs WHERE date > '$today' ORDER BY date DESC";

 

Wacko formats for database dates just make everything hard work.  Best, obviously, is if the dates in the db-table are yyyy-mm-dd format (type = date). $today is date("Y-m-d").

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.