Clinton Posted April 24, 2008 Share Posted April 24, 2008 Here's the Output: If 4/24/2008 > 3/10/2008 then show Warning Message. Clinton Andersen is due for a CDL Medical Evaluation! It Expires 4/10/2008 If 4/24/2008 > 3/23/2009 then show Warning Message. Bobby Brown is due for a CDL Medical Evaluation! It Expires 4/23/2009 ******* Clearly 4/24/08 is not greater than 3/23/09 ********* If 4/24/2008 > 3/17/2008 then show Warning Message. Monster Cookie is due for a CDL Medical Evaluation! It Expires 4/17/2008 Here's the Code: $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("clintona_SLC",$dbhandle) or die("Can not open SLC Database"); $result = mysql_query("SELECT lname, fname, cdlmedical FROM training ORDER BY lname"); $now = date('n/j/Y'); while ($row=mysql_fetch_assoc($result)){ extract($row); $cdlmedicalexpire = strtotime($cdlmedical.'+ 12 months'); $cdlmedicalexpire = date('n/j/Y',$cdlmedicalexpire); $cdlmedical = strtotime($cdlmedical.'+ 11 months'); $cdlmedical = date('n/j/Y',$cdlmedical); echo "<br>If $now > $cdlmedical then show Warning Message."; if ($now > $cdlmedical) { echo "<center> $fname $lname is due for a CDL Medical Evaluation! It Expires $cdlmedicalexpire </center>"; }} ?> What's wrong here? Link to comment https://forums.phpfreaks.com/topic/102739-solved-query-not-working/ Share on other sites More sharing options...
Clinton Posted April 24, 2008 Author Share Posted April 24, 2008 I had to change back the times to 0000-00-00 in order for it to be recognized. Once I did that it worked. Link to comment https://forums.phpfreaks.com/topic/102739-solved-query-not-working/#findComment-526206 Share on other sites More sharing options...
947740 Posted April 24, 2008 Share Posted April 24, 2008 You could just use timestamps and then convert it back to the date when echoing. I presume that is what you mean when you made your post, while I was making this post. Link to comment https://forums.phpfreaks.com/topic/102739-solved-query-not-working/#findComment-526207 Share on other sites More sharing options...
PFMaBiSmAd Posted April 24, 2008 Share Posted April 24, 2008 Sql date and datetime data types (and Unix timestamp) can be compared and sorted directly. The reason being, they are in a most significant digit to least significant digit yyyy-mm-dd format. Higher dates have higher values and lower dates have lower values. A format like 3/17/2008 is not arranged in most significant digit to least significant digit and cannot be sorted or compared. Link to comment https://forums.phpfreaks.com/topic/102739-solved-query-not-working/#findComment-526228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.