Hi everyone,
I've this wierd problem....i don't know what to do abt it....can anyone pls help?
I've written a code for searching from MySQL database. This code works very well, but when i tried merging it with the design code written by my colleague...the query is not working....
This is my previous code which works perfectly....
<?php
include('dbconntry.php');
$sql = "SELECT * FROM properties";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<br>";
echo "<br>";
echo "Found the following entries in the database:";
echo "<br />";
echo "<br />";
$result = mysql_query("SELECT * FROM properties WHERE city='$city' OR zip='$zip' OR br='$br'");
echo "<table border='1'>
<tr>
<th>Address</th>
<th>City</th>
<th>Zip</th>
<th>Location</th>
<th>Rent</th>
<th>Deposit</th>
<th>Square Feet</th>
<th>Available</th>
<th>Bed Room</th>
<th>Bath</th>
<th>Family Room</th>
<th>Fireplace</th>
<th>Type</th>
<th>Terms</th>
<th>Carpetting</th>
<th>Garage</th>
<th>Yard</th>
<th>Pet</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['zip'] . "</td>";
echo "<td>" . $row['area'] . "</td>";
echo "<td>" . $row['rent'] . "</td>";
echo "<td>" . $row['deposit'] . "</td>";
echo "<td>" . $row['sqft'] . "</td>";
echo "<td>" . $row['available'] . "</td>";
echo "<td>" . $row['br'] . "</td>";
echo "<td>" . $row['bath'] . "</td>";
echo "<td>" . $row['familyrm'] . "</td>";
echo "<td>" . $row['fireplace'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['terms'] . "</td>";
echo "<td>" . $row['carpetting'] . "</td>";
echo "<td>" . $row['garage'] . "</td>";
echo "<td>" . $row['yard'] . "</td>";
echo "<td>" . $row['pet'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo "<br>";
$num=mysql_numrows($result);
echo "Total number of entries: $num";
if(!$result)
{
echo "No data.";
}
?>
and i've inserted the same in the design, but doesn't work...here it is....
<div id="contentright">
<h1 class="listings">Our Properties For Rent</h1>
<!-- Start refine search bar //-->
<div id="refine">
<form id="form1" action="search1.php" method="post">
<fieldset>
<label for="city">Search:</label>
<select name="city" id="city" onchange="buildCounties(this.value);">
<option value="1" selected="selected">All</option>
<option value="2">Eugene</option>
<option value="3">Springfield</option>
</select>
<label for="county">ZipCode:</label>
<div id="countylist">
<select name="zip" id="zip">
<option value="0">All Zip Codes</option>
<option value="97401">97401</option>
<option value="97402">97402</option>
<option value="97403">97403</option>
<option value="97404">97404</option>
<option value="97405">97405</option>
<option value="97408">97408</option>
<option value="97412">97412</option>
<option value="97440">97440</option>
<option value="97455">97455</option>
<option value="97477">97477</option>
<option value="97478">97478</option>
<option value="97482">97482</option>
</select>
</div>
<label for="bedrooms">Bedrooms:</label>
<select name="br" id="br" class="small">
<option value="0">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<br />
<br />
<input type="image" src="img/button_refinesearch.gif" alt="Refine Search" class="sub" />
<input type="hidden" name="submit" value="1" />
</fieldset>
</form>
</div>
<!-- End refine search bar //-->
<h2 class="large">Searching Properties <span class="green">For Rent</span></h2>
<!--<p class="results">We currently have <strong>3</strong> matches, matches 1 - 3 shown</p>-->
<br class="clear" />
<?php
include('dbconntry.php');
$sql="SELECT * FROM properties";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$result = mysql_query("SELECT * FROM properties WHERE city='$city' OR zip='$zip' OR br='$br'");
$num=mysql_num_rows($result);
echo " ";
echo "We currently have $num matches for your search";
echo "<br />";
echo "<br />";
$i=0;
while ($i < $num) {
$address=mysql_result($result,$i,"address");
$city=mysql_result($result,$i,"city");
$rent=mysql_result($result,$i,"rent");
$type=mysql_result($result,$i,"type");
$comments=mysql_result($result,$i,"comments");
?>
<h3 class="listhead"><span class="listcount">
<?php echo "$city";?></span><a href=""><?php echo "$address<br>";?></a></h3>
<div class="listing">
<div class="listingdetails">
<a href=""><img src="" width="136" height="102" /></a>
<p><?php echo "<br>$$rent - $type <br> Comments: $comments<br>";?></p>
</div>
<ul>
<li class="details"><a href="">View Details</a></li>
</ul>
</div>
<?php $i++;
}
if(!$result)
{
echo "No data.";
}
?>
I've only changed the display of the records from table to a different type...
Pls help.....
Thanks