如何正确显示"未找到结果"在PHP?

时间:2015-08-10 14:31:53

标签: php

在此代码中,我想显示是否找到结果。这里的逻辑错误是,即使现在找到结果,它仍然会显示"没有找到结果"。

        $search = $_POST['lastname'];

        $result = mysql_query("SELECT * FROM contact where lastname = '$search'");

        $trap = mysql_query("SELECT lastname FROM contact where lastname = '$search'");

        //for trapping input
        if($trap!=$search){
            echo "No Results Found";
        }
        if($trap==$search){
            echo " ";
        }
        //the logical error is that the "No Results Found" is still displayed even if the results are now found  


        echo"<table border=1>";
        echo"<tr><th>Lastname</th><th>Firstname</th><th>Address</th></tr>";

        while($row=mysql_fetch_array($result))
        {   
            echo "<tr>" . "<td>" .$row['lastname']."</td>" . "<td>" .$row['firstname']. "</td>" . "<td>" .$row['address']. "</td>" . "</tr>";
        }
        echo "</table>";

0 个答案:

没有答案