KurveMedia
12-15-2008, 03:46 AM
I'm not sure what im doing wrong with the following code. The purpose of the code is to take input from a drop down and 2 text fields and search the database and display the information that matches the criteria. The first criteria is the drop down which is to choose whether you want to search by the name of the business or the main category that its in. the second is where you enter the name of the business or the main category that business is in. the second text field is to enter the city if your trying to find a particular business type in a particular city.not sure what im doing wrong, but its not bring up any information or its just bringing up everything in that city in the database no mater what kind of business. below is the code that im using
$link = mysql_connect($host,$username,$password);
if (!$link)
{
echo "we could not establish a connection to the sql server! please retry later";
exit;
}
if (!mysql_select_db($db))
{
echo "we could not connect to the database! please retry later";
exit;
}
$where = "WHERE 1 ";
if($_GET['name'] != "") {
$where .= " AND ".$_GET['type']." like '%".$_GET['name']."%'";
}
if($_GET['city'] != "")
{
$where .= " AND BusinessCity like '%".$_GET['city']."%'";
}
//$sql = "SELECT * FROM listings WHERE BusinessCity = '".$_GET['city']."' AND ".$_GET['type']." = '".$_GET['name']."'";
$sql = "SELECT * FROM listings ".$where;
$namecatquery = mysql_query($sql);
if($namecatquery != true)
{
echo "error";
}
$count = mysql_num_rows($namecatquery);
?>
<?php
while($array = mysql_fetch_array($namecatquery))
{
$link = mysql_connect($host,$username,$password);
if (!$link)
{
echo "we could not establish a connection to the sql server! please retry later";
exit;
}
if (!mysql_select_db($db))
{
echo "we could not connect to the database! please retry later";
exit;
}
$where = "WHERE 1 ";
if($_GET['name'] != "") {
$where .= " AND ".$_GET['type']." like '%".$_GET['name']."%'";
}
if($_GET['city'] != "")
{
$where .= " AND BusinessCity like '%".$_GET['city']."%'";
}
//$sql = "SELECT * FROM listings WHERE BusinessCity = '".$_GET['city']."' AND ".$_GET['type']." = '".$_GET['name']."'";
$sql = "SELECT * FROM listings ".$where;
$namecatquery = mysql_query($sql);
if($namecatquery != true)
{
echo "error";
}
$count = mysql_num_rows($namecatquery);
?>
<?php
while($array = mysql_fetch_array($namecatquery))
{