create a table for the search result

advertisements

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'];

    }

?>


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