View Single Post
Old 06-15-2011, 01:30 PM  
eMonk
Confirmed User
 
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
Ok, I had to use the as clause in the query to separate the 2 different column names.

Here's what the code looks like now:

Code:
<?php
include("../includes/connect.php");
$id = 17;
$query = "SELECT city.city_id AS city_id_1, city.city_name, model_in_city.model_id, model_in_city.city_id AS city_id_2, model_in_city.city_display
          FROM city, model_in_city
	  WHERE model_in_city.model_id = $id
          AND model_in_city.city_display = 1";
if ($result = $db->query($query)) 
{
  echo "<select name=\"select\">";
  while ($row = $result->fetch_assoc()) 
  {
    $name = $row['city_name'];
	$city_id_1 = $row['city_id_1'];
	$city_id_2 = $row['city_id_2'];
    echo "<option value=\"$city_id_1\">$name</option>";
	/* if($row['city_id'] == $city_id)
       {
           echo "<option selected>$name</option>";
       } */
  }
  echo "</select>";
  echo "$city_id_2"; // just checking to make sure this value is correct.
  $result->free();
}
$db->close();
?>
Now, how can I echo the selected value if the option value = $city_id_2

I think I may have to perform another query since the cities are entered in by city id number in the model_in_city table to fetch the name of the city instead to display as selected.

Note: I commented out the if statement in the code above.
eMonk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote