Hi,
I have 2 tables in my db such as city and location. I want to get the particular city from the city table and find the corresponding locations names for that city. Please check the following code,
---------------------------------------------------------------
$id = $_GET['city'];
$con1 = mysql_connect("localhost","lasith","lasith123");
if (!$con1){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con1);
$cities = mysql_query("SELECT * FROM cities where name = '" .$id. "'") or die(mysql_error());
while($city = mysql_fetch_array($cities)){
$city_id = $city['id'];
}
$result1 = mysql_query("SELECT * FROM locations where city = '" .$city_id. "'") or die(mysql_error());
$names = "";
while($row1 = mysql_fetch_array($result1)){
if (empty($names)){
$names = $row1['name'];
}else {
$names = $names . "," . $row1['name'];
}
}
---------------------------------------------------------------
The first select statement is working. Even I can see value for $city_id when debugging. Second select statement always return empty results without any errors. I feel something wrong with the type of $city_id. Can you guys help me to resolve this.
Note:
The city field of locations table has the type of varchar(10) and the ID field of cities table has type int(6)



