Jump to content

Missing rows when taking data from database


Cagecrawler

Recommended Posts

I have the following code which is used to list all of the stock items in my system.  The only problem is that it isn't showing all of the rows found by the MySQL query.  I have 4 dummy data items, but only 3 are shown.  My code is below:
[code]
<?php

//Connect to DB
include("connect.php");

$sql="SELECT * FROM stock ORDER BY itemname";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
echo "<center>";
echo "<h1>Current Items in Stock</h1>";
echo "Return to <a href=\"index.php\">Home</a>";
echo "<table border=1>";
echo "<tr>";
echo "<td>Item Name</td>";
echo "<td>Item Type</td>";
echo "<td>Quantity</td>";
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>".$row['itemname']."</td>";
echo "<td>".$row['itemtype']."</td>";
echo "<td>".$row['quantity']."</td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
?>
[/code]
Any ideas why?
you are creating 2 arrays. No need to do it.
try this
[code]<?php

//Connect to DB
include("connect.php");

$sql="SELECT * FROM stock ORDER BY itemname";
$query=mysql_query($sql);
echo "<center>";
echo "<h1>Current Items in Stock</h1>";
echo "Return to <a href=\"index.php\">Home</a>";
echo "<table border=1>";
echo "<tr>";
echo "<td>Item Name</td>";
echo "<td>Item Type</td>";
echo "<td>Quantity</td>";
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>".$row['itemname']."</td>";
echo "<td>".$row['itemtype']."</td>";
echo "<td>".$row['quantity']."</td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
?>[/code]

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.