Chi Shen Chi Shen - 10 months ago 44
MySQL Question

display "result not found" if no result in database

i want to display a message "result not found" if user search something that do not exits in database.

here is my code but it didnt works.

can somebody tell me what's wrong with my code?

include 'database_conn.php';

$eventCat = $_GET['catID'];
$eventVenue =$_GET['venueName1'];

$sqlSearch = " SELECT * FROM te_events

WHERE catID = '$eventCat' AND venueID = '$eventVenue'";

$rsSearch = mysqli_query($conn,$sqlSearch) or die(mysqli_error($conn));

<!DOCTYPE html>

while ($row =mysqli_fetch_assoc($rsSearch)){
//extract each field$
$id = $row ["eventID"];
$title = $row ["eventTitle"];
$desc = $row ["eventDescription"];
$venueId = $row ["venueID"];
// $venue = $row ["venueName"];
// $location = $row ["location"];
$categoryId = $row ["catID"];
//$category = $row ["catDesc"];
$eStart = $row ["eventStartDate"];
$eEnd = $row ["eventEndDate"];
$ePrice = $row ["eventPrice"];


//start a row
//output the url
echo"<div><a href =\"allDetails.php?eventID=$id\">
echo "No event found! Please select other option.\n";





Answer Source

Check the amount of rows and then write your code based on the result.


if($rows > 0) {

while ($row = mysqli_fetch_assoc($rsSearch)){

// code for results


} else {

// legend for no results


Edit: you don't need to ask the mysql result array whether the line is populated or empty, the line itself will never be empty, it will simply not exist in the array if the query didn't find any data.