0
<?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)

4

1 回答 1

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>";
于 2013-01-24T03:12:55.630 回答