Forum Moderators: coopster

Message Too Old, No Replies

PHP Search Query From Two Tables

         

dynamicdude

1:02 am on Mar 8, 2006 (gmt 0)



Hello guys,
I have a problem as I am stuck in searching part of my website where I have to search for Location,Number of Beds and Price and display my result with a thumbnail of the property with small description.
I have made two tables one for image and one to register the property details.
The HTML code for the seach page is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Search Page</title>
<meta name="author" content="Dwijen Shilu"/>
<meta name="keywords" content="Torbay,Agent,Property"/>
<meta name="revised" content="4th Feburary 2006"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>

<body>

<h1> Search Page </h1>
<!-- <form name="search" action="http://www.fbi.gov" target="search"> -->
<form name="search" action="search1.php" target="search">
<p>Property Type :-
<select name="Prop_Type" size="1" tabindex="1">
<option selected="selected">Apartment</option>
<option>Flat</option>
<option>Villa</option>
</select>
</p>
<p> Number of Beds:-
<select name="Number of Beds" size="1">
<option value="1" selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</p>
<p>Minimum Price:-
<input name="minPrice" type="text" id="minPrice" size="10" maxlength="15" />
per day </p>
<p>Maximum Price:-
<input name="maxPrice" type="text" id="maxPrice" size="10" maxlength="15" />
per day
</p>
<p>Location:-
<select name="Location" size="1">
<option value="1" selected="selected">Boven Tracey</option>
<option>Brixham</option>
<option>Cornwell</option>
<option>Darthmouth</option>
<option>Paignton</option>
<option>Shaldon</option>
<option>South Devon</option>
<option>Stoke Gabriel</option>
<option>Teignmouth</option>
<option>Totnes</option>
</select>
</p>
<p>&nbsp;</p>
<input type="submit" name="Submit" value="Search" />
</form>
<p>&nbsp;</p>
</body>

</form>

</html><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Search Page</title>
<meta name="author" content="Dwijen Shilu"/>
<meta name="keywords" content="Torbay,Agent,Property"/>
<meta name="revised" content="4th Feburary 2006"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>

<body>

<h1> Search Page </h1>
<!-- <form name="search" action="http://www.fbi.gov" target="search"> -->
<form name="search" action="search1.php" target="search">
<p>Property Type :-
<select name="Prop_Type" size="1" tabindex="1">
<option selected="selected">Apartment</option>
<option>Flat</option>
<option>Villa</option>
</select>
</p>
<p> Number of Beds:-
<select name="Number of Beds" size="1">
<option value="1" selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</p>
<p>Minimum Price:-
<input name="minPrice" type="text" id="minPrice" size="10" maxlength="15" />
per day </p>
<p>Maximum Price:-
<input name="maxPrice" type="text" id="maxPrice" size="10" maxlength="15" />
per day
</p>
<p>Location:-
<select name="Location" size="1">
<option value="1" selected="selected">Boven Tracey</option>
<option>Brixham</option>
<option>Cornwell</option>
<option>Darthmouth</option>
<option>Paignton</option>
<option>Shaldon</option>
<option>South Devon</option>
<option>Stoke Gabriel</option>
<option>Teignmouth</option>
<option>Totnes</option>
</select>
</p>
<p>&nbsp;</p>
<input type="submit" name="Submit" value="Search" />
</form>
<p>&nbsp;</p>
</body>

</form>

</html><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Search Page</title>
<meta name="author" content="Dwijen Shilu"/>
<meta name="keywords" content="Torbay,Agent,Property"/>
<meta name="revised" content="4th Feburary 2006"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>

<body>

<h1> Search Page </h1>
<!-- <form name="search" action="http://www.fbi.gov" target="search"> -->
<form name="search" action="search1.php" target="search">
<p>Property Type :-
<select name="Prop_Type" size="1" tabindex="1">
<option selected="selected">Apartment</option>
<option>Flat</option>
<option>Villa</option>
</select>
</p>
<p> Number of Beds:-
<select name="Number of Beds" size="1">
<option value="1" selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</p>
<p>Minimum Price:-
<input name="minPrice" type="text" id="minPrice" size="10" maxlength="15" />
per day </p>
<p>Maximum Price:-
<input name="maxPrice" type="text" id="maxPrice" size="10" maxlength="15" />
per day
</p>
<p>Location:-
<select name="Location" size="1">
<option value="1" selected="selected">Boven Tracey</option>
<option>Brixham</option>
<option>Cornwell</option>
<option>Darthmouth</option>
<option>Paignton</option>
<option>Shaldon</option>
<option>South Devon</option>
<option>Stoke Gabriel</option>
<option>Teignmouth</option>
<option>Totnes</option>
</select>
</p>
<p>&nbsp;</p>
<input type="submit" name="Submit" value="Search" />
</form>
<p>&nbsp;</p>
</body>

</form>

</html>

And the Half Baked PHP file is here
<?php
require_once("../mysql_connect.php");
$row = 10;
/*foreach ($_POST['Prop_Type'] as $pt) {
$in1 .= "'" . $pt . "',";
}
$in1 = substr($in1,0,strlen($pt)-1);
foreach ($_POST['Location'] as $pt) {
$in2 .= "'" . $pt . "',";
}
$in2 = substr($in2,0,strlen($pt)-1);
*/

$q = "SELECT * FROM t_prop_det WHERE Prop_Type IN (" . $in1 . ") AND Location IN (" . $in2 . ") AND price BETWEEN " . $_POST['minPrice'] . " AND " . $_POST['maxPrice'];
#$result = mysql_query($q);
echo "<table align=center width=500>";
echo "<tr bgcolor='#FAC88B' class='NiceSmallBold' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><th>Property Type</th><th>Prop_Desc</th><th>No of Bed</th><th>Location </th></tr>\n";
if ($result=mysql_query($q)) {
while ($row=mysql_fetch_row($result)) {
echo "<tr bgcolor='#FDE9D0'><td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'>".$row[0]."</td>";
echo "<td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><p align='center'>".$row[1]."</td>";
echo "<td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><p align='center'>".$row[2]."</td>";
echo "<td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><p align='center'>".$row[3]."</td></tr>\n";
}
} else {
echo "<!-- SQL Error ".mysql_error()." -->";
}
echo "</table>";

?>

Please Help Me!
With the code how can i display images from images table along with the property details from the property table.

bomburmusicmallet

1:16 am on Mar 8, 2006 (gmt 0)

10+ Year Member



You need to join the 2 tables on some common key in your query.