我可以知道如何创建用于显示查询搜索结果的HTML表格吗?
这是我的搜索代码
<?php
//This connects the file to your database.
// Change the "database-username & database-password" to the one you've setup already.
mysql_connect ("localhost", "root","") or die (mysql_error());
mysql_select_db ("smpi");
$search = $_POST['search'];
$sql = mysql_query("select * from maklumat_pc where FName like '%$search%'");
while ($row = mysql_fetch_array($sql)){
echo '<br/> Agensi: '.$row['Agensi'];
echo '<br/> Jabatan: '.$row['Jabatan'];
echo '<br/> Work Group: '.$row['Work_Group'];
echo '<br/> Computer Name: '.$row['Computer_Name'];
echo '<br/> Kategori Infra: '.$row['Kategori_Infra'];
echo '<br/> Nama Pengguna: '.$row['Nama_Pengguna'];
echo '<br/> Jawatan: '.$row['Jawatan'];
echo '<br/> Gred Jawatan: '.$row['Gred_Jawatan'];
}
?>
答案 0 :(得分:1)
像这样,
echo '<table>';
echo '<thead><tr><th>Agensi</th><th>Jabatan</th></thead>';
while ($row = mysql_fetch_array($sql)){
echo '<tr>';
echo '<td>'.$row['Agensi'].'</td>';
echo '<td>'.$row['Jabatan'].'</td>';
echo '</tr>';
}
echo '</table>';
答案 1 :(得分:1)
将此数据用于表格格式
<?php
mysql_connect ("localhost", "root","") or die (mysql_error()); //This connects the file to your database. Change the "database-username & database-password" to the one you've setup already.
mysql_select_db ("smpi");
$search = mysql_real_escape_string($_POST['search']);
$sql = mysql_query("SELECT * FROM maklumat_pc WHERE FName LIKE '%$search%'");
?>
<table>
<thead>
<tr>
<th>Agensi</th>
<th>Jabatan</th>
<th>Work Group</th>
<th>Computer Name</th>
<th>Kategori Infra</th>
<th>Nama Pengguna</th>
<th>Jawatan</th>
<th>Gred Jawatan</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array($sql))
{
?>
<tr>
<td><?php echo $row['Agensi'];?></td>
<td><?php echo $row['Jabatan'];?></td>
<td><?php echo $row['Work_Group'];?></td>
<td><?php echo $row['Computer_Name'];?></td>
<td><?php echo $row['Kategori_Infra'];?></td>
<td><?php echo $row['Nama_Pengguna'];?></td>
<td><?php echo $row['Jawatan'];?></td>
<td><?php echo $row['Gred_Jawatan'];?></td>
</tr>
<?php
}
?>
</tbody>
</table>
警告强>
此扩展程序自PHP 5.5.0起已弃用,将来将被删除
答案 2 :(得分:0)
试试这段代码:
echo '<table border="1">';
while ($row = mysql_fetch_array($sql)){
echo '<tr>';
echo '<td> Agensi: '.$row['Agensi'].'</td>';
echo '<td> Jabatan: '.$row['Jabatan'].'</td>';
echo '<td> Work Group: '.$row['Work_Group'].'</td>';
echo '<td> Computer Name: '.$row['Computer_Name'].'</td>';
echo '<td> Kategori Infra: '.$row['Kategori_Infra'].'</td>';
echo '<td> Nama Pengguna: '.$row['Nama_Pengguna'].'</td>';
echo '<td> Jawatan: '.$row['Jawatan'].'</td>';
echo '<td> Gred Jawatan: '.$row['Gred_Jawatan'].'</td>';
echo '</tr>';
}
echo '</table>';