View Single Post
Old 06-15-2011, 04:36 PM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,115
Home now,

as I said in icq, that version was so you could see what was happening all the way through.

To do it from one query like you were trying to do would look like this: http://www.madspiders.com/selecttest1.php

Code:
<?php
//error_reporting(0);
$dbhost = "XXXXX";
$dbuser = "XXXXX";
$dbpass = "XXXXX";
$db = mysql_connect($dbhost, $dbuser, $dbpass);
$dbname="select_test";
$selected=mysql_select_db($dbname);

// for testing
$id = 1;

$query  ="select a.city_id, a.city_name, b.city_display from city a ";
$query .="left outer join model_in_city b on a.city_id=b.city_id and b.city_display>0 and b.model_id=" . $id . " ";
$query .="order by a.city_name";

$city_result=mysql_query($query,$db);
if ($city_result) 
{
    echo "<select name=select multiple size=8>";
    while ($cityrow = mysql_fetch_array($city_result)) 
    {
      echo "<option value=" . $cityrow['city_id']; 
      if($cityrow['city_display']==1)
      {
          echo " selected ";
      }
      echo ">" . $cityrow['city_name'] . "</option>";
    }
    echo "</select>";
}
else
{
  echo "no city result mysql error=" . mysql_error() . "<br>\n";
}
?>
You said on yours that it was not marking the options as selected. When you get back, post up the actual code you have so we can take a look.

.
__________________
All cookies cleared!

Last edited by sarettah; 06-15-2011 at 04:41 PM..
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote