搜索框的问题

时间:2014-05-05 10:54:04

标签: php mysql search

我的搜索表单存在另一个问题...我有三个搜索字段 [年] [月] [名称] 但这是我遇到问题的地方,我希望如果mysql_num_rows <= 0它应回显没有找到搜索关键字的记录。这是我的代码......

if ((empty($_POST['son_admin_query_year'])) && (empty($_POST['son_admin_query_month'])) && (empty($_POST['son_name']))) {

    echo "<b>please search for something the boxes are empty.</b>";

} else {

    if (
    isset($_POST['son_admin_query_year']) || isset($_POST['son_admin_query_month']) || isset($_POST['son_name'])) {
        $search_data = $_POST['son_name'];
        $search_year = $_POST['son_admin_query_year'];
        $search_mnth = $_POST['son_admin_query_month'];


        $search_data = mysql_real_escape_string($search_data);
        $search_year = mysql_real_escape_string($search_year);
        $search_mnth = mysql_real_escape_string($search_mnth);

        include_once("../../includes/db.php");

        $query = "SELECT * FROM importers WHERE im_name LIKE '%".$search_data."%' OR year LIKE '%".$search_year."%' OR month LIKE '%".$search_mnth."%'";
        $results = mysql_query($query) or die(mysql_error());

        echo "ROWS number ="."::".mysql_num_rows($results);
        if (mysql_num_rows($results) >= 1) {

            echo "<div id='search_result'>";
            echo '<table class="table table-striped table-bordered table-hover">';
            echo "<tr><th>Importers Name</th><th>Address</th><th>Month</th><th>Year</th><th>View More</th>
                                        </tr>";

            while ($row = mysql_fetch_array($results)) {
                $add = $row['address'];
                $im_name = $row['im_name'];
                $state = $row['state'];
                $phone = $row['phone'];
                $email = $row['email'];
                $cac_no = $row['coc_no'];
                $son_mth = $row['month'];
                $son_year = $row['year'];

                $but_more = "<a href='view_more.php?cac=".$cac_no."'><button class='btn btn-success'>View More</button>";

                echo "<tr><td>";
                echo $im_name;
                echo "</td><td>";
                echo $add;
                echo "</td><td>";
                echo $son_mth;
                echo "</td><td>";
                echo $son_year;
                echo "</td><td>";
                echo $but_more;
                echo "</td><td>";
                echo "</td></tr>";

            }
            echo "</table>";
            echo "</div>";
            //echo "<div id='print_data'><button type='button' class='btn' id='print'>Print PDF</button></div>";

        } else {
        }
    }
}

0 个答案:

没有答案