Jump to content

Problem with Date() ans SELECT, please help


patheticsam

Recommended Posts

Hi,

 

I'm a little bit new to php and I'm working on a script to display upcoming events.

 

Here's the script I have :

 

<?php 


require_once('../admin/config.php');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}


$date = Date("Y-m-d");
$data = mysql_query("SELECT * FROM events WHERE event_date > $date ORDER by event_date") 
or die(mysql_error());

while($info = mysql_fetch_array( $data ))

			{					
?>
							<div class="indent-bottom17 border-bottom p8">
								<?php echo $date; ?>
								<h3 class="p4-1"><?php echo $info['event_city'].", ".$info['event_state']; ?></h3>
								<h6 class="p4-1">Course title : <?php echo $info['event_title']; ?></h6>
								   <a href="view_event.php?cmd=view&id=<?php echo $info['event_id']; ?>">View details...</a>
							</div>
<?php
			}
?>

 

I don't get any errors and the script seems to work except for the part that it also displays events from the past...it ignores the condition : SELECT * FROM events WHERE event_date > $date ORDER by event_date

 

I don't know if i'm doing this right but if anyone can point me to a solutions it would be really appreciated...Thanks!!

Literal dates in a query are strings and need to be enclosed by single-quotes WHERE event_date > '$date'

 

Without the single-quotes, a date looks like a math subtraction problem: WHERE event_date > 2012-08-08 evaluates to WHERE event_date > 1996

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.