2014-03-12 82 views

回答

1
$opt = "Office"; 
foreach($categories as $rowcat){     
    if($row->catname == $opt) { 
    echo '<option value="'.$row->catname.'" selected="selected">'.$rowcat->catname.'</option>';     
    } 
    else { 
    echo '<option value="'.$row->catname.'">'.$rowcat->catname.'</option>'; 
    } 
} 
+0

這一個爲我工作!謝謝 –

1
foreach($categories as $rowcat){     

echo '<option value="'.$rowcat->catname.'" '.($rowcat->catname=='Office') ? 'selected="selected"' : ''.'>'.$rowcat->catname.'</option>';     
} 
+0

雖然我會使用''===良好做法;) –

相關問題