Hello All,
I am a php newbie and trying to figure out how to automatically pull text from a database based on what the current datetime is. 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.
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?
Thanks so much for your time and expertise!