crobinson42
05-19-2010, 10:35 PM
i have a drop down box, which i would like to have the already stored variable selected when the drop down list is produced. here's my example:
<select name="location1"><option selected="selected" value="0">
<?php
require_once('../connectvars.php');
$query = "SELECT * FROM location ORDER BY name ASC";
$result = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($result)){
$id = $row['id'];
$name = $row['name'];
$address_city = $row['address_city'];
$address_state = $row['address_state'];
$a = if($location1 == '$id'){ echo 'selected="selected"';}
echo '<option value="'.$id.'" '.$a.'> '.$name.', '.$address_city.' '.$address_state.'</option>';
}
?></select>
As you can see, i am trying to create the matching id's and have that option selected..but it doesn't work
Parse error: syntax error, unexpected T_IF
<select name="location1"><option selected="selected" value="0">
<?php
require_once('../connectvars.php');
$query = "SELECT * FROM location ORDER BY name ASC";
$result = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($result)){
$id = $row['id'];
$name = $row['name'];
$address_city = $row['address_city'];
$address_state = $row['address_state'];
$a = if($location1 == '$id'){ echo 'selected="selected"';}
echo '<option value="'.$id.'" '.$a.'> '.$name.', '.$address_city.' '.$address_state.'</option>';
}
?></select>
As you can see, i am trying to create the matching id's and have that option selected..but it doesn't work
Parse error: syntax error, unexpected T_IF