hgkhkhk Posted November 11, 2017 Share Posted November 11, 2017 I have built a search engine for my booking system. It works properly but the only issue I cannot resolve is how to display a "no results" message if nothing has been found in the system. I tried putting an }else{ echo 'no results'; } at the end the very end of the code, but when results are found, it still displays the "no results" message. Does anyone know where I can insert this line to ensure that "no results" does not show up when results actually turn up and to ensure it only shows, when no actual results have been found? Thank you. <?php $server="localhost"; $username="root"; $password=""; $dbname="equipment"; $conn=mysqli_connect($server,$username,$password,$dbname); $server="localhost"; $username="root"; $password=""; $dbname="qmb_ground_floor"; $conn2=mysqli_connect($server,$username,$password,$dbname); $server="localhost"; $username="root"; $password=""; $dbname="qmb_level_01"; $conn3=mysqli_connect($server,$username,$password,$dbname); $server="localhost"; $username="root"; $password=""; $dbname="qmb_level_02"; $conn4=mysqli_connect($server,$username,$password,$dbname); ?> <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="resultsstyle.css"> <link rel="icon" href="Icon.jpg"> <title>Search</title> </head> <body> <div class="header"> <img class="icon" src="Icon.jpg"> <div class="search">Search </div> </div> <div class="select">Results </div> <?php if (isset($_POST['submit-search'])){ $search=mysqli_real_escape_string($conn,$_POST['search']); $sql="SELECT * FROM bookings WHERE equipment LIKE'%$search%' OR start_time LIKE '%$search%'OR end_time LIKE '%$search%'OR selected_date LIKE '%$search%'"; $result=mysqli_query($conn, $sql); $queryResult=mysqli_num_rows($result); if(empty($_POST['search'])){ echo '<span class="empty">Search box was empty. Please try again.</span>'; }else{ if($queryResult>0){ while($row=mysqli_fetch_assoc($result)){ echo " <span class='e'>Equipment: <span class='first'>".htmlspecialchars($row['equipment'])."</span></span><br> <span class='bd'>Booking Date: <span class='second'>".htmlspecialchars($row['selected_date'])."</span></span><br> <span class='st'>Start Time: <span class='third'>".htmlspecialchars($row['start_time'])."</span></span><br> <span class='et'>End Time: <span class='fourth'>".htmlspecialchars($row['end_time'])."</span></span><br> <span class='n'>Notes: <span class='fifth'>".htmlspecialchars($row['notes'])."</span></span><br><br><br><br> "; } } $search=mysqli_real_escape_string($conn2,$_POST['search']); $sql="SELECT * FROM bookings2 WHERE room LIKE'%$search%' OR start_time LIKE '%$search%'OR end_time LIKE '%$search%'OR selected_date LIKE '%$search%'"; $result=mysqli_query($conn2, $sql); $queryResult=mysqli_num_rows($result); if($queryResult>0){ while($row=mysqli_fetch_assoc($result)){ echo " <span class='e'>Room: <span class='first'>".htmlspecialchars($row['room'])."</span></span><br> <span class='bd'>Booking Date: <span class='second'>".htmlspecialchars($row['selected_date'])."</span></span><br> <span class='st'>Start Time: <span class='third'>".htmlspecialchars($row['start_time'])."</span></span><br> <span class='et'>End Time: <span class='fourth'>".htmlspecialchars($row['end_time'])."</span></span><br> <span class='n'>Notes: <span class='fifth'>".htmlspecialchars($row['notes'])."</span></span><br><br><br><br> "; } } $search=mysqli_real_escape_string($conn3,$_POST['search']); $sql="SELECT * FROM bookings3 WHERE room LIKE'%$search%' OR start_time LIKE '%$search%'OR end_time LIKE '%$search%'OR selected_date LIKE '%$search%'"; $result=mysqli_query($conn3, $sql); $queryResult=mysqli_num_rows($result); if($queryResult>0){ while($row=mysqli_fetch_assoc($result)){ echo " <span class='e'>Room: <span class='first'>".htmlspecialchars($row['room'])."</span></span><br> <span class='bd'>Booking Date: <span class='second'>".htmlspecialchars($row['selected_date'])."</span></span><br> <span class='st'>Start Time: <span class='third'>".htmlspecialchars($row['start_time'])."</span></span><br> <span class='et'>End Time: <span class='fourth'>".htmlspecialchars($row['end_time'])."</span></span><br> <span class='n'>Notes: <span class='fifth'>".htmlspecialchars($row['notes'])."</span></span><br><br><br><br> "; } } $search=mysqli_real_escape_string($conn4,$_POST['search']); $sql="SELECT * FROM bookings4 WHERE room LIKE'%$search%' OR start_time LIKE '%$search%'OR end_time LIKE '%$search%'OR selected_date LIKE '%$search%'"; $result=mysqli_query($conn4, $sql); $queryResult=mysqli_num_rows($result); if($queryResult>0){ while($row=mysqli_fetch_assoc($result)){ echo " <span class='e'>Room: <span class='first'>".htmlspecialchars($row['room'])."</span></span><br> <span class='bd'>Booking Date: <span class='second'>".htmlspecialchars($row['selected_date'])."</span></span><br> <span class='st'>Start Time: <span class='third'>".htmlspecialchars($row['start_time'])."</span></span><br> <span class='et'>End Time: <span class='fourth'>".htmlspecialchars($row['end_time'])."</span></span><br> <span class='n'>Notes: <span class='fifth'>".htmlspecialchars($row['notes'])."</span></span><br><br><br><br> "; } } } } ?> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Barand Posted November 11, 2017 Share Posted November 11, 2017 code tags and indentation, please. Quote Link to comment Share on other sites More sharing options...
hgkhkhk Posted November 11, 2017 Author Share Posted November 11, 2017 I have managed to solve the problem. Thanks to anyone for trying to help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.