zoukankan      html  css  js  c++  java
  • 从数据库中选取数据形成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>
    

      

  • 相关阅读:
    Power of Cryptography
    Radar Installation
    Emag eht htiw Em Pleh
    Help Me with the Game
    89. Gray Code
    87. Scramble String
    86. Partition List
    85. Maximal Rectangle
    84. Largest Rectangle in Histogram
    82. Remove Duplicates from Sorted List II
  • 原文地址:https://www.cnblogs.com/shanmao/p/3473436.html
Copyright © 2011-2022 走看看