从数据库中选取数据形成select标签
添加文章时用代码如下:
<select name="NClass" id="NClass" class="sel"> <?php $querySel = "select * from nclass"; $result_sub = mysql_query($querySel) or die(mysql_error()); $i = 0; while($row_sub=mysql_fetch_array($result_sub)) { $result_show[$i] = $row_sub; echo "<option value='". $result_show[$i]['ID'] ."'>". $result_show[$i]['ClassName'] ."</option>"; $i++; } ?> </select>
编辑文章时用如下代码:
<select name="HotelID" id="HotelID" class="sel"> <?php $querySel = "select * from hotel where AddUser=".$_SESSION['UserID']; $result_sub = mysql_query($querySel) or die(mysql_error()); $i = 0; while($row_sub=mysql_fetch_array($result_sub)) { $result_show[$i] = $row_sub; if ($row['HotelID'] == $result_show[$i]['ID']) $sel_c = "selected"; echo "<option ".$sel_c." value='". $result_show[$i]['ID'] ."'>". $result_show[$i]['HName'] ."</option>"; $sel_c = ""; $i++; } ?> </select>
----------------
Lynx
The quieter you become,the more you are able to hear.