Reputation: 11
may I know how to create a HTML table for displaying my queries search results?
here is my code for search
<?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'];
}
?>
Upvotes: 1
Views: 105
Reputation: 111
Try this code:
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>';
Upvotes: 0
Reputation: 1002
Something like this,
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>';
Upvotes: 1
Reputation: 38584
use this for show data as Table Format
<?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>
Warning
This extension is deprecated as of PHP 5.5.0, and will be removed in the future
Upvotes: 1