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
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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.