在 html table 中显示 php mssql 查询数组
display php mssql query array in html table
我是 php 的完全业余爱好者。我尝试了几十种不同的东西,大部分是在浏览这里时发现的。我已经研究了几个小时了,我开始失去理智了。缺乏真正的知识,我现在只是猜测。
我敢肯定此代码已完全被篡改,并且会严重冒犯你们中的许多人。
目标是将mssql查询结果显示成漂亮的HTMLtable。
到目前为止,除了 table headers 之外,没有显示任何内容。查询应该 return 几十行。
这是当前代码,有什么建议吗?
<?php
// Open db connection
$dbc = mssql_connect('host', 'sa', 'password');
if (!$dbc || !mssql_select_db('dbname', $dbc)) {die('Unable to connect or select database!');}
// Select queries
$query = mssql_query("SELECT [name],[customer],[start_time],[end_time],[status] FROM dbo.reservation ORDER BY last_update DESC");
// display the results!
if (!mssql_num_rows($query)) {
echo 'No records found';
} else {
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Customer</th>
<th>Start Time</th>
<th>End Time</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mssql_fetch_row($query)) {
echo'<tr>';
echo'<td>'. $row['name']."</td>";
echo'<td>'. $row['customer'].'</td>';
echo'<td>'. $row['start_time'].'</td>';
echo'<td>'. $row['end_time'].'</td>';
echo'<td>'. $row['status'].'</td>';
echo'<tr>';
}
?>
</tbody>
</table>
<?php
}
?>
注意:这是一个内部站点,我需要使用 mssql_connect。
您正在尝试使用列名索引来自 mssql_fetch_row()
的结果行,但此函数仅 returns 具有数字索引的数组。使用 mssql_fetch_array()
获取可以使用列名索引的数组。
我是 php 的完全业余爱好者。我尝试了几十种不同的东西,大部分是在浏览这里时发现的。我已经研究了几个小时了,我开始失去理智了。缺乏真正的知识,我现在只是猜测。
我敢肯定此代码已完全被篡改,并且会严重冒犯你们中的许多人。
目标是将mssql查询结果显示成漂亮的HTMLtable。 到目前为止,除了 table headers 之外,没有显示任何内容。查询应该 return 几十行。
这是当前代码,有什么建议吗?
<?php
// Open db connection
$dbc = mssql_connect('host', 'sa', 'password');
if (!$dbc || !mssql_select_db('dbname', $dbc)) {die('Unable to connect or select database!');}
// Select queries
$query = mssql_query("SELECT [name],[customer],[start_time],[end_time],[status] FROM dbo.reservation ORDER BY last_update DESC");
// display the results!
if (!mssql_num_rows($query)) {
echo 'No records found';
} else {
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Customer</th>
<th>Start Time</th>
<th>End Time</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mssql_fetch_row($query)) {
echo'<tr>';
echo'<td>'. $row['name']."</td>";
echo'<td>'. $row['customer'].'</td>';
echo'<td>'. $row['start_time'].'</td>';
echo'<td>'. $row['end_time'].'</td>';
echo'<td>'. $row['status'].'</td>';
echo'<tr>';
}
?>
</tbody>
</table>
<?php
}
?>
注意:这是一个内部站点,我需要使用 mssql_connect。
您正在尝试使用列名索引来自 mssql_fetch_row()
的结果行,但此函数仅 returns 具有数字索引的数组。使用 mssql_fetch_array()
获取可以使用列名索引的数组。