Hi, I have been trying to debug this error all day and am having problems. The script connects to the database and displays the results as as it should, however, when it loops, I get the error "Warning: mysql_fetch_array(): 3 is not a valid MySQL result resource". I tried to use
echo "<hr />".$query."<hr />";exit();
but found no error with my query, I'm sure the problem lies in my loop. Am I doing this wrong? Can anyone offer any help?
My code is;
$query="SELECT make, model, price, year, fuel, miles, transmission, description, image, id FROM stock";
$result=mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);
mysql_close();
if ($num > 0){
echo "<p>We currently have $num cars in stock;</p>";
echo "<table>";
$i = 0;
for ($i=0; $i < $num; $i++)
{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo " <tr>
<th></th>
<th>$row[make]</th>
</tr>
<tr>
<td><a href=\"details.php?id=$row[id]\"><img src=\"view-image.php?id=$row[id]\" width='200' alt='error- no image found' />Click for more images</a></td>
<td>$row[description]</td>
</tr>
<tr>
<td>Miles: $row[miles]</td>
<td>Transmission: $row[transmission]</td>
</tr>
<tr>
<td>Fuel Type: $row[fuel]</td>
<td>Price: £$row[price]</td>
</tr>";
echo '</table>';
mysql_free_result($result);
}
}
}
?>