I’m new in PHP, it’s learning process. Now I’m getting tired to fix this issue. I’ve a mysql database where a few row exits. Like :
1) pro_no_sleep 2) pro_country 3) pro_state 4) pro_city etc..
When i run a query to get this database content, it’s doesn’t show duplicate value content. for example. In my pro_no_sleep row 2 value are same: Like 1
pro_no_sleep
1
1
2
3
So when i run following query with php it’s doesn’t show duplication value content. It’s show only unique value content. Like 2 and 3.
$search = mysql_query("SELECT * FROM property_step1 WHERE pro_no_sleep = '$people' OR
pro_country = '$country' OR pro_state = '$region' OR pro_city = '$destination'");
I didn’t use % sign in my query because of html form table has fix value from select tag.
Php Code:
<?php
if (isset($_GET['Submit']) && $_GET['Submit'] == "Search") {
require_once("func.php");
$people = mysql_real_escape_string(htmlspecialchars(trim($_GET['people'])));
$country = mysql_real_escape_string(htmlspecialchars(trim($_GET['country'])));
$region = mysql_real_escape_string(htmlspecialchars(trim($_GET['region-depart'])));
$destination = mysql_real_escape_string(htmlspecialchars(trim($_GET['destination'])));
$from = mysql_real_escape_string(htmlspecialchars(trim($_GET['from'])));
$to = mysql_real_escape_string(htmlspecialchars(trim($_GET['to'])));
$upload = "user/content/uploaded";
$search = mysql_query("SELECT * FROM property_step1 WHERE pro_no_sleep = '$people' OR pro_country = '$country' OR pro_state = '$region' OR pro_city = '$destination'");
$num = mysql_num_rows($search);
if ($num == 1) {
echo " " . $num . " result found.";
while ($result = mysql_fetch_array($search)) {
echo "<div id='rightsearch'>";
$propertyid = (int) $result['propertyid'];
$getimg = mysql_query("SELECT * FROM property_step3 WHERE propertyid =
'$propertyid' ORDER BY imgname LIMIT 1");
$protitle_d = $result['pro_title'];
$country_d = $result['pro_country'];
$region_d = $result['pro_state'];
$destination_d = $result['pro_city'];
$pro_des_d = $result['pro_des'];
$pro_type_d = $result['pro_type'];
$pro_no_bed_d = $result['pro_no_bed'];
$pro_no_bath_d = $result['pro_no_bath'];
$pro_no_sleep_d = $result['pro_no_sleep'];
$getreview = mysql_query("SELECT rating FROM property_review WHERE p_id = '$propertyid'");
$num_review = mysql_num_rows($getreview);
while ($reimg = mysql_fetch_array($getimg)) {
$img = $reimg['imgname'];
echo "<a href='details.php?propertyid=$propertyid'>";
echo '<img src="' . $upload . '/' . $img . '" width="' . 100 . '" height=" ' . 100 . '" />';
echo "</a>";
}
echo "<h2>$protitle_d</h2>";
echo "<p>$country_d, $region_d, $destination_d</p>";
//echo myTruncate($pro_des_d, 100) . "<br/>";
echo $pro_des_d . "<br/>";
echo "<h5>$pro_type_d, $pro_no_bed_d bedroom";
if ($pro_no_bed_d > 1) {
echo $plural = "s";
}
echo ",";
echo " $pro_no_bath_d bath";
if ($pro_no_bath_d > 1) {
echo $plural2 = "s";
}
echo ",";
echo " $pro_no_sleep_d sleep";
if ($pro_no_sleep_d > 1) {
echo $plural3 = "s";
}
echo "</h5>";
echo "$num_review review";
echo "</div>";
} // first while statement
} // second if statment
else {
echo "<div id='rightsearch'>";
echo "No result found";
echo "</div>";
}
}
?>
Here’s your problem:
mysql_num_rowsreturns the number of rows in the result. So you check if the result contains only one row, iterate over all the rows (remember, there’s only one!) and do something.What you need to do is check if the result contains at least one row.