MOD EDIT: Post moved into its own thread; original thread can be found here.
Installer;10725927 wrote:Store the dates and text in a database, then retrieve the text for the current date something like this:
mysql_query = "SELECT my_text FROM my_table WHERE start_date <= DATE() AND end_date >= DATE()";
I know this is a very old thread, but I am looking to do this same thing, and have not been able to get this query to work. Can anyone help? I have a table set up with three columns, start_date, end_date and text. I would like to pull the text field based on what datetime it is... so the field will auto update when the current date is in the range of the new row. So, the text will update on Monday at noon or something like that. Right now I am trying this:
$now = date("Y-m-d H:i:s");
$query="SELECT text FROM database WHERE $now BETWEEN start_date AND end_date";
$result=mysql_query($query) or die("A MySQL error has occurred.<br />Error: (" . mysql_error() . ") " );
$text = mysql_result($result,0);
echo $text;
I am getting this error:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 2
So it seems like the query is not pulling any results. Is that correct? Not sure how to go about this, any ideas?