search table and echo message based on results

Hi guys!

I’m pretty okay at PHP, but i’m doing something a bit outside my comfort zone. I have a table full of MAC IDs for routers. I’m helping the company that built them organize a recall.

the goal is to have a search of a mac return results based on the build date (also in the table), and also return a message if the mac isn’t found.

Table:
units
| mac | date |
|00-00-00-00-00-00 | 2014/10/17 |

php:
[php]<?PHP
$mac= $_POST[‘mac’];

include “…/assets/connect.php”;

$query = mysql_query(“SELECT mac,date_built FROM units WHERE mac=’$mac’");
$results = $query->getResults();

if( sizeof($results) > 0 ){
// look up the documentation for date_diff, DateTime, and DateInterval.
$interval = date_diff( $results[0]->date_built, new DateTime(‘2014/10/19’) );

if( $interval->invert = 1 ){ // i think this is how to test for before/after, but double-check me.
echo “recall”;
}
else {
echo “unit okay”;
}
}
else {
echo “not found”;
}

?>[/php]

my form is feeding the correct data to the script, but I think the script is wrong. the goal is that if the date is prior to 10-19-14, it displays recall, after- no recall. and mac not found should display that as well.

Thanks for any help you can provide!

Josh

I think you need to change:

[php]if( $interval->invert = 1 )[/php]

To:

[php]if($interval->d > 0)[/php]

It’s just a guess I didn’t test anything.

Sponsor our Newsletter | Privacy Policy | Terms of Service