Kenneth W. A
Kenneth W. A

Reputation: 1

The First Data Do Not Show When Getting Data From MySQL Table to PHP

I am trying to fetch data from an sql database into a php table. Yet the problem is that the first data from my database doesn't appear into the table. Did i commit a mistake ? The following is my code....

<?php
include "koneksi.php";
$sql    = mysqli_query ($link,
        "SELECT * FROM absen");
$data   = mysqli_fetch_array($sql);
?>

<html>
<head>
<title>Data Mahasiswa</title>
</head> 
<body>

<p><h2><b><center>DATA MAHASISWA</center></b></h2></p>


<table border="2" style="1000px;" align="center">
    <tr bgcolor="blue">
        <th>No</th>
        <th>Nama</th>
        <th>NIM</th>
        <th>Jenis Kelamin</th>
    </tr>
    <?php
    while($data)
        while($data = mysqli_fetch_array($sql)){
    ?>
     <tr>
        <td><?php echo $data['no']; ?></td>
        <td><?php echo $data['nama']; ?></</td>
        <td><?php echo $data['nim']; ?></</td>
        <td><?php echo $data['jenis_kelamin']; ?></</td>
    </tr>
    <?php } ?>

</table>
<center><b><h3><a href="Website.html"><img src="Capture.jpg" width="100px"> 
</a></h3></b></center>
</p>
</body>
</html>

Upvotes: 0

Views: 284

Answers (1)

E3Im
E3Im

Reputation: 330

You are doing mysqli_fetch_array() twice. Fixed code:

    <?php
    include "koneksi.php";
    $sql    = mysqli_query ($link,
            "SELECT * FROM absen");

    ?>

    <html>
    <head>
    <title>Data Mahasiswa</title>
    </head> 
    <body>

    <p><h2><b><center>DATA MAHASISWA</center></b></h2></p>


    <table border="2" style="1000px;" align="center">
        <tr bgcolor="blue">
            <th>No</th>
            <th>Nama</th>
            <th>NIM</th>
            <th>Jenis Kelamin</th>
        </tr>
        <?php
          while($data = mysqli_fetch_array($sql)){
        ?>
         <tr>
            <td><?php echo $data['no']; ?></td>
            <td><?php echo $data['nama']; ?></</td>
            <td><?php echo $data['nim']; ?></</td>
            <td><?php echo $data['jenis_kelamin']; ?></</td>
        </tr>
        <?php } ?>

    </table>
    <center><b><h3><a href="Website.html"><img src="Capture.jpg" width="100px"> 
    </a></h3></b></center>
    </p>
    </body>
    </html>

Upvotes: 1

Related Questions