我正在创建一个包含SQL数据的PHP Web应用程序,并希望根据下拉选项显示日志。 我已经为列数据创建了下拉列表。然后我将选择用户名,它应显示与该用户名相关的数据将列表。 请帮我。 提前致谢
以下是源代码:
<?php
$serverName = "TestDB,1433"; //serverName\instanceName
$connectionInfo = array(
"Database" => "Database123",
"UID" => "sa",
"PWD" => "Pass.124"
);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn)
{
echo "Connection established.<br />";
}
else
{
echo "Connection could not be established.<br />";
die(print_r(sqlsrv_errors() , true));
}
$sql = "SELECT DISTINCT username from [Database123].[dbo].[LOG] ";
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false)
{
die(print_r(sqlsrv_errors() , true));
}
echo "<table border='1'>
<table class='table'>
<thead>
<tr>
<th class='w'> User name</th>
<th> Log Time</th>
</tr>
</thead>";
echo "</select>";
while ($row = sqlsrv_fetch_Array($stmt, SQLSRV_FETCH_BOTH))
{
echo "<option value=";
echo $row['username'];
echo ">";
echo $row['username'];
echo "</option>";
echo "<select>";
sqlsrv_close($conn);
?>
答案 0 :(得分:1)
使用像这样的选择框
echo "<select>";
while ($row = sqlsrv_fetch_Array($stmt, SQLSRV_FETCH_BOTH))
{
echo "<option value=".$row['username'].">".$row['username']."</option>";
}
echo "</select>";
sqlsrv_close($conn);