【问题标题】:Populate listbox with data from database使用数据库中的数据填充列表框
【发布时间】:2013-01-24 02:48:16
【问题描述】:
<?php
ini_set("display_errors","on");
$conn = new COM("ADODB.Connection");
   try {
   $myServer = "WTCPHFILESRV\WTCPHINV";
   $myUser = "sa";
   $myPass = "P@ssw0rd";
   $myDB = "wtcphitinventory";   
   $connStr = "...conn string...";
   $conn->open($connStr); 
         if (! $conn) {
            throw new Exception("Could not connect!");
        }
   }
   catch (Exception $e) {
      echo "Error (File:): ".$e->getMessage()."<br>";
   }   
if (!$conn)
  {exit("Connection Failed: " . $conn);}
    $sql_exp = "select * from dbo.PC"; 
  $rs = $conn->Execute($sql_exp);
 echo "<table><tr><th>Desktop Number</th></th></tr>";
   while (!$rs->EOF) {
       set_time_limit(0);    
       echo "<td>CP # <br>".$rs->Fields("PC_Number")."</td>";           
      $rs->MoveNext();
   }   
   echo "</table>";   
   $rs->Close();   
       ?>  

我想要一个列表框,而不是仅仅打印数据库中 PC_Number 的所有数据。我所能做的就是回应它,我很难插入一个选择。我想要一个表单方法和一个 select(listbox)

【问题讨论】:

    标签: php html sql-server


    【解决方案1】:

    在while语句中创建列表框。

    echo "<table border='1' cellpadding='1' cellspacing='0' id='rounded-corner'><tr><th>Desktop Number</th></th></tr>";
    
    
       echo "<tr><td><select name='selectionField'>";
       while (!$rs->EOF) {
           set_time_limit(0);
           echo "<option value=".$rs->Fields('PC_Number')." >".$rs->Fields('PC_Number')."</option>";
          $rs->MoveNext();
       }   
       echo "</td></tr></table>";
    

    【讨论】:

    • THAAAAAAAAAAAAAAAAAAAAAAAAANK 你!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多