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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.