You keep fetching where you don't need to. You have three fetches in total, the one in the loop is the useful one, the one prior is manually printed, and the one for $pans is completely abandoned.
Replace this:
PHP Code:
<?php
if ($num_pans > 0) {
$pans = mysql_fetch_assoc($results);
$panname = ($row['panname']);
$stock = ($row['stock']);
$price = ($row['price']);
?>
<!-- Create Stock table structure -->
<table border=1, cellpadding=3>
<!-- Loop through the items in the pans table -->
<?php for ($i=0; $i<$row_num; $i++)
{
$row = mysql_fetch_assoc($results);
}; ?>
<tr><th>Pan Name</th><th>In Stock</th><th>Price (pence)</th></tr>
<tr><td><?php echo $row['panname']; ?></td>
<td> <?php echo $row['stock']; ?></td>
<td> <?php echo $row['price']; ?></td></tr>
<?php
//Print out the items in the table loop
while ($row = mysql_fetch_assoc($results)) {
echo "<tr>";
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>";
}
// close the connection
mysql_close($connection);
}
?>
With this:
PHP Code:
<?php
if ($num_pans > 0) {
?>
<!-- Create Stock table structure -->
<table border="1" cellpadding="3">
<tr><th>Pan Name</th><th>In Stock</th><th>Price (pence)</th></tr>
<!-- Loop through the items in the pans table -->
<?php
while ($row = mysql_fetch_assoc($results))
{
print ('<tr>');
printf('<td>%s</td>', implode('</td><td>', $row));
print ('</tr>');
}
// close the connection
mysql_close($connection);
}
?>