<?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的所有数据。我所能做的就是回应它,我很难插入一个选择。我想有一个表单方法帖子和一个选择(列表框)
答案 0 :(得分: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>";