I have code like this, it shows data when tehre is data but if there is no data i want to say "no records"

where am i going wrong?

<?php
require_once('db_conf.php');

$sql = "SELECT * FROM tbl_holidayspecials WHERE fld_country = '$countryname' AND fld_state = '$statename' AND fld_city = '$cityname'";
$result = mysql_query($sql);

if (!$result) {
  
echo "No Records";

}

while ($row = mysql_fetch_assoc($result)) {

		   $ids = $row["id"];
		   $hotelname = $row["fld_destination"];
	
echo $hotelname;
}

Recommended Answers

All 2 Replies

use mysql_num_rows

if (mysql_num_rows($result) == 0) {
    echo "No records found";
}

PERFECT !
Thank you it works I knew there was something to do with the rows it fetched.
Thank you again you dont know how much you helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.