从数据库中选取数据形成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>

  

posted @ 2013-12-13 16:43  山貓  阅读(598)  评论(0编辑  收藏  举报