Forum Moderators: coopster
What I am trying to do is, check if there is today's date set in the publish_date field, if there is none, pull out one row at random, and update it's publish_date field to current date.
I tried to get this working by updating the field manually thru phpmyadmin, and then the 1st bit works, but then, it fails to update any fields when all records have publish_date as '0000-00-00' which is default to a date column.
Please review my below code and let me know where I have gone wrong. I have spent hours trying to get this working; it's 2am and my eyes are heavy I cannot do any more on this today. Please, please let me know your opinions and corrections on the code below.
<?php
$result = mysql_query("SELECT * FROM quotes WHERE publish_date=CURDATE()");
if($result) {
$sql = mysql_fetch_array($result);
echo stripslashes($sql['quote'] . " ~ <cite>" . $sql['author'] . "</cite>");
} else {
$sel = mysql_query("SELECT * FROM quotes WHERE publish_date='0000-00-00' ORDER BY rand() LIMIT 1");
$sql=mysql_fetch_array($sel);
$id = $sql['quote_id'];
$sql = "UPDATE quotes SET publish_date=CURDATE() WHERE quote_id=$id";
}