比较来自搜索的ID和数据库中的条目(PHP MYSQL)

时间:2019-03-06 01:33:16

标签: php mysql

我有这个。

<form id="" class="searchbar" action="searchAppt.php" method="get">
       <input id="" size="5" type="number" name="terms" min="0"  class = "sbar" placeholder="Enter appointment ID " oninput="validity.valid||(value='');"
                   onblur="if (this.value == '') {
                                this.value = 'Enter ID #';
                            }"
                   onfocus="if (this.value == 'Enter ID #') {
         this.value = '';
     }"/>&nbsp;&nbsp;
            <button type="submit" class = "btn">
                <span class="glyphicon glyphicon-search"></span> Search 
            </button>
        </form>

传递给这个。现在,它获得所有ID的“赞”,但我基本上是想查看他们搜索的号码是否与约会表中的ID相匹配。 (约会ID)约会ID只是“ id”

if (filter_has_var(INPUT_GET, "terms")) {
    $terms_str = filter_input(INPUT_GET, 'terms', FILTER_SANITIZE_NUMBER_INT);
} else {
    echo "There were no appointments found.";
    include ('includes/footer.php');
    exit;
}
            //explode the search terms into an array
         //   $terms = explode(" ", $terms_str);


  $sql = "SELECT * FROM appointments WHERE 1";
            foreach ($terms as $term) {
                $sql .= " AND id LIKE '%$term%' AND email = '". $_SESSION['email'] ."' 
                ";
            }

            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                echo "<br /> <br /> <center><h1> Your Tickets </h1></center><br /> <hr><br /> <table border = 1><tr><th>Ticket #</th><th>First Name</th><th>Last Name</th><th>Phone #</th><th>Building</th><th>Room #</th><th>Issue</th><th>Appt. Start Time</th><th>Appt. End Time</th></tr>";
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    echo "<tr><td>".$row["id"]."</td><td>".$row["fname"]."</td><td>".$row["lname"]."</td><td>".$row["phonenum"]."</td><td>".$row["building"]."</td><td>".$row["room"]."</td><td>".$row["issue"]."</td><td>".$row["start_time"]."</td><td>".$row["end_time"]."</td></tr>";
                }
                echo "</table>";
            } else {
                echo "<br /> <br />Your search <i>'$terms_str'</i> did not match any appointments";
                include ('includes/footer.php');
                exit;
            }

        ?>

0 个答案:

没有答案