Jump to content


Photo

Displaying message when no search results found


  • Please log in to reply
2 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 27 September 2006 - 12:46 PM

Hi

This code searches a database with given criterion:

$sql = "SELECT * FROM properties WHERE price >= '$pricemin' and price <= '$pricemax'";
	
if ($bedrooms > 0) {
	$sql .= " and bedrooms = '$bedrooms'";
}

if ($bathrooms > 0) {
	$sql .= " and bathrooms = '$bathrooms'";
}

if ($type != "Any") {
	$sql .= " and type = '$type'";
}

if ($term == 0) {
	$sql .= " and rentalorpurchase = 'purchase'";
} elseif ($term == 1) {
	$sql .= " and rentalorpurchase = 'rent'";
}

$sql .= " ORDER BY price DESC";

$result = mysql_query ($sql) or die (mysql_error());

if (!($result)) {
	$_GET['msg'] = "Sorry We Found No Matches For Your Search";
}

// Include results page	
include_once ("search.html");


The problem is if(!($result)) this does not seem to trap when there are no search results found...any ideas?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 27 September 2006 - 12:57 PM

use mysql_num_rows()


if (mysql_num_rows($result) == "0") {
	$_GET['msg'] = "Sorry We Found No Matches For Your Search";
}



#3 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 27 September 2006 - 01:01 PM

cool, just realised !($result) will just check to see if the query was a success
http://thewebsolutionprovider.com - A Solution For Everything Web!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users