Forum Moderators: coopster
one of the elemnts of the record, has a drop down box to populate it (its populated from another database).
getting it to display is coo, but i ant get it to have the default value to be whats already in the database
(types is in car database, type is in car_types(this is where i put Small/Med/Large)database) When a car is added, its assigned one of the values in the list (selected by the user)
now when it comes to EDIT these, thats when it goes a bit squiffy
$sql = "SELECT * FROM cars WHERE car_id = '$upid'";
$rs1=(mysql_query($sql,$conn));while($row = mysql_fetch_array($rs1)){
echo ("<br>You chose the following record:<br><br>");
echo ("<input type=\"hidden\" name=\"updateid[]\" value=\"{$upid}\"> ");
echo ('Reg No:<input type="text" name="reg" size="8" value="'.$row["reg_no"].'"> ');
echo ('Make:<input type="text" name="make" size="8" value="'.$row["make"].'"> ');
echo ('Model:<input type="text" name="model" size="8" value="'.$row["model"].'">');
echo ("type:" .$row['type']);
$typevar=$row['type'];
$sql1 ="SELECT types FROM car_types";
$query = mysql_query($sql1,$conn);echo '<select name="type1">';
while
($row = mysql_fetch_array($query))
{
if($typevar = $row['types']){
echo '<option value="',$row['types'],', selected="selected">',$row['types'],'</option>';
}else
echo '<option value="',$row['types'],'">',$row['types'],'</option>';}
echo '</select>';}
echo('</form>')
?>
any ideas?
echo ("type:" .$row['type']);
$typevar=$row['type'];
if($typevar == $row['types']){
echo '<option value="',$row['types'],', selected="selected">',$row['types'],'</option>';
}else
echo '<option value="',$row['types'],'">',$row['types'],'</option>';
Thats my logic for it, i cant see whats not happening
echo '<select name="type1">';
while ($row = mysql_fetch_array($query)) {
echo '<br>typevar: ',$typevar,' - row[types]: ',$row['types'];
if($typevar == $row['types']) {
echo '<option value="',$row['types'],'" selected="selected">',$row['types'],'</option>';
} else {
echo '<option value="',$row['types'],'">',$row['types'],'</option>';
}
echo '</select>';
}
I also made a change to the option display, did you check the page source to check the html? I am guessing that you didn't. Before changing this code, look at your page source and see if the 'selected' is getting echoed but just not working due to syntax issues
this original line is wrong
echo '<option value="',$row['types'],', selected="selected">',$row['types'],'</option>';
the one in the code I put above is correct
$types = array();
$sql1 ="SELECT types FROM car_types";
$query = mysql_query($sql1,$conn);
while($row = mysql_fetch_assoc($query))
$types[] = $row['types'];
#
$sql = "SELECT * FROM cars WHERE car_id = '".mysql_real_escape_string($upid)."'";
$rs1=(mysql_query($sql,$conn));
#
while($row = mysql_fetch_array($rs1)){
#
echo ("<br>You chose the following record:<br><br>");
echo ("<input type=\"hidden\" name=\"updateid[]\" value=\"{$upid}\"> ");
echo ('Reg No:<input type="text" name="reg" size="8" value="'.$row["reg_no"].'"> ');
echo ('Make:<input type="text" name="make" size="8" value="'.$row["make"].'"> ');
echo ('Model:<input type="text" name="model" size="8" value="'.$row["model"].'">');
echo ("type:" .$row['type']);
#
$typevar=$row['type'];
#
foreach($types as $type) {
echo '<select name="type1">';
#
if($type == $typevar) {
echo '<option value="',$type],', selected="selected">',$type,'</option>';
} else {
echo '<option value="',$type,'">',$type,'</option>';
}
}
echo '</select>';
}
echo('</form>')
?>
Try that and see where that gets you. Note that this is untested.
[edit]
wow, took me awhile to post this :-P