Jump to content

[SOLVED] Query not working. :-(


Clinton

Recommended Posts

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

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.