I'm trying to retrieve a table from MySql database, but my code returns incorrect data. here is my code below
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "net_trade";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (mysqli_connect_errno()) {
die("Connection failed: " . mysqli_connect_error());
}
echo "<link rel='stylesheet' type='text/css' href='style.css'>";
echo "<h1>NET TRADE</h1>";
echo "<div align='center'>";
echo "<ul>";
echo "<li><a class='nav' href='inventory.php'>INVENTORY</a></li>";
echo "<li><a class='nav' href='supplier.php'>SUPPLIER</a></li>";
echo "<li><a class='nav' href='customer.php'>CUSTOMER</a></li>";
echo "<li><a class='nav' href='sales.php'>SALES</a></li>";
echo "</ul>";
echo "</div>";
echo "<form method='POST' action='create_supplier.html'>
<input type='SUBMIT' class='style19' name='new_item' value='Add New Item'></form>";
echo "<table class='TFtable'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Quantity</th>";
echo "<th>Name</th>";
echo "<th>Brand</th>";
echo "<th>Model</th>";
echo "<th>Serial</th>";
echo "<th>Date Supplied</th>";
echo "<th>Supplier</th>";
echo "</tr>";
$result = mysqli_query($conn, "SELECT * FROM inventory");
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
echo "<tr>";
echo "<td>".$row['0']."</td>";
echo "<td>".$row['1']."</td>";
echo "<td><a href='edit.php?id=".$row['0'].">".$row['2']."</a></td>";
echo "<td>".$row['3']."</td>";
echo "<td>".$row['4']."</td>";
echo "<td>".$row['5']."</td>";
echo "<td>".$row['6']."</td>";
echo "<td>".$row['7']."</td>";
echo "</tr>";
}
mysqli_free_result($result);
}else {
echo "0 results";
}
mysqli_close($conn);
echo "</table>";
?>
the result should be this...
but my code returns something like this..
the result skips a row from the database table.. thats my main prob