Re: Query to MySQL

From: Date: Wed, 25 Sep 2002 23:26:28 +0000
Subject: Re: Query to MySQL
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-16010@lists.php.net to get a copy of this message
Marlene You need to convert the current date to a string of the form "yyy-mm-dd hh:mm:ss" and write your query as follows $datestring = date("Y-m-d H:i:s", $some_time_stamp_integer); - or for this very day today $datestring = date("Y-m-d H:i:s"); // returns today if no optional timestamp given $query = "SELECT eventmonth FROM $create_calendar_tablename WHERE eventdate >=\"".$datestring."\" LIMIT 19"; or alternatively $query = "SELECT eventmonth FROM $create_calendar_tablename WHERE eventdate >=\"$datestring\" LIMIT 19"; note the escaped quotation marks in each case. if you are not in the habit of concatenating strings with those "dots" this assumes you have stored dates in your table as type datetime rather timestamp. timestamp is an integer. (number of seconds since ages ago - 1972 I think) datetime is a string - e.g. "2002-09-24 10:30:00" hope this helps ----- Original Message ----- From: "Marlene Burckhalter" <mburckhalter@triad.rr.com> To: <php-windows@lists.php.net> Sent: Thursday, September 26, 2002 5:02 AM Subject: [PHP-WIN] Query to MySQL I am trying to display an event calendar in an html document ( I am a beginner, I had to start small). My problem is the following query displays all the records instead of just the ones with the event date greater than or equal to the current date. Any suggestions to a begginer? Here is a snipplet: $query = "SELECT eventmonth FROM $create_calendar_tablename WHERE eventdate >= 'currentdate()' LIMIT 19"; $result = mysql_query($query); if(!$result) error_message(sql_error()); while($query_data = mysql_fetch_array($result)) { echo $query_data["eventmonth"],"<P>"; }

« previous php.windows (#16010) next »