2015-02-17 103 views
0

我做了一个搜索,看看我是否能找到我的答案,但这完全是我没有使用正确的术语,所以随时在我的背面打我头部,并链接到正确的页面,如果我错过了:)PHP使用getResults根据结果筛选和回应响应

我在做什么是搜索一个特定的项目,在这种情况下MAC地址表。如果找不到,我想回显“未找到”;

如果找到了,我想检查该MAC的日期的另一行。如果日期早于指定日期,则回显“回忆”;

如果MAC比日期更新,则回显“MAC okay”;

这里是什么样的能看起来像一个示例:

| mac    | date  | 
| 00-00-00-00-00-00 | 2014/10/17 | 

我的形式写得好,它给了正确的信息到PHP,但在这里它是无论如何:

<form action="results.php"> 
mac id 
<input type="text" name="mac"> 
<input type="submit"> 
</form> 

这里是来自results.php的PHP。它连接表没有问题。我认为这个问题的核心是我的查询:

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

include "connect.php"; 

$query = mysql_query(“SELECT mac,date 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"; 
} 

?> 

回答

0

假设你要检查对当前的日期,这里是我的尝试:

include "connect.php"; 

$mac= $_POST[‘mac’]; 

$result = mysql_query("SELECT * FROM units WHERE mac='".$mac."'"); // query 

// no results 
if (!$result) { 
    echo 'not found'; 
} else { 
    $mac_date = $result[0]->date; 
    // check if its newer 
    if(strtotime($mac_date) > strtotime('now')) { 
    echo 'MAC ok'; 
    } 
    // check if its older 
    if(strtotime($mac_date) < strtotime('now')) { 
    echo 'recall'; 
    } 
} 
+0

这让我在正确的方向。谢谢 – 2015-02-18 04:21:15

+0

没问题,很高兴我可以帮忙 – cch 2015-02-18 04:22:08