How do you query a record for today's date. Here is what I have but it does not work. // Retrieve all the data from the "Date" table $result = mysql_query("SELECT curdate()") or die(mysql_error()); // store the record of the "Date" table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry Any assistance would be appreciated.
$result = mysql_query("SELECT curdate() AS today") or die(mysql_error()); // store the record of the "Date" table into $row $row = mysql_fetch_array( $result ); //SHOULD BE AVAILABLE AS $row['today']; I'm not totally sure on what you're trying to accomplish, because curdate() just returns the server's current date. It isn't field dependant. Are you trying to retrieve the date of a record in the table.
I have dated records in the database and would like to only show the record that matches today's date.
What is the column name of the date field and the column data type (date, datetime, timestamp, etc...)? It would be something like (This may vary depending on the data type): SELECT column_names... FROM my_table WHERE DATE_FORMAT(date_column, '%Y-%m-%d') = CURDATE();
The column field is "date" and it is listed on the server in date format yyyy-mm-dd The confusing part of is that I named the table "Date" and I have a column name "Date" for the date of the record. Should I change the table name.
Here is the entire script, if that helps <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title></title> </head> <body> <?php // Make a MySQL Connection mysql_connect("secureserver.net", "name", "xxxxxxx") or die(mysql_error()); mysql_select_db("viewtext") or die(mysql_error()); // Retrieve all the data from the "Date" table $result = mysql_query("SELECT * FROM Date") or die(mysql_error()); // store the record of the "Date" table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry echo "$Date: ".$row['Date']; echo "$Email: ".$row['Email']; echo "$Par1:".$row['Par1']; echo "$Par2:".$row['Par2']; echo "$Par3:".$row['Par3']; echo "$Par4:".$row['Par4']; echo "$Par5:".$row['Par5']; ?> </body> </html>
It's probably not a good idea to use that name for the table and field name but it should work if you use backticks when querying on that table/field. Select `date` FROM `date` WHERE `date`... etc...
I am trying to display the entire row of data where the date in one field matches the current date. This is what I have but I am stuck, it only returns the date. <body> <?php // Make a MySQL Connection mysql_connect("secureserver.net", "database", "xxxxxxxx") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); // Retrieve all the data from the "Emailing" table $result = mysql_query("SELECT `Date` FROM `Emailing` WHERE DATE_FORMAT(Date,'%Y-%m-%d') = CURDATE()") or die(mysql_error()); // store the record of the "Date" table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry echo "<h1>Real Estate Term of the Day</h1>"; echo "$Date".$row['Date']; echo "<br>"; echo "<br>"; echo "$Par1".$row['Par1']; echo "<br>"; echo "<br>"; echo "$Par2".$row['Par2']; echo "<br>"; echo "<br>"; echo "$Par3".$row['Par3']; echo "<br>"; echo "<br>"; echo "$Par4".$row['Par4']; echo "<br>"; echo "<br>"; echo "$Par5".$row['Par5']; echo "<br>"; echo "<br>"; ?> </body>
Use this when querying your db. The cur_date simply gets the current date for you from the users computer. $cur_date = date("Y/m/d"); // Retrieve all the data from the "Emailing" table $result = mysql_query("SELECT * FROM Emailing WHERE DATE = '$cur_date'");