I have the below script to select and output all products in my database where the type value is 2:
PHP Code:
<?php
$u = "*********";
$p = "******";
$d = "*********";
mysql_connect("**************",$u,$p);
@mysql_select_db($d) or die("Fatal MySQL Error");
$query = "SELECT * FROM products WHERE type=2";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$i = 0;
while ($i<=$num) {
$name = mysql_result($result,$i,"name");
$desc = mysql_result($result,$i,"desc");
$id = mysql_result($result,$i,"id");
$price = mysql_result($result,$i,"price");
$msg = "<tr>\n";
$msg .= "<td width=\"15%\">\n";
$msg .= "<a href=\"product.php?id=$id\">$name</a><br>$price\n";
$msg .= "</td>\n";
$msg .= "<td width=\"85%\">\n";
$msg .= "$desc\n";
$msg .= "</td>\n";
$msg .= "</tr>\n";
echo($msg);
$i++;
}
?>
Instead of outputting my table full of products, it outputs the table with this above it:
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 4 in e:\domains\s\stuff4web.co.uk\user\htdocs\flash-catalogue.php on line 31
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 4 in e:\domains\s\stuff4web.co.uk\user\htdocs\flash-catalogue.php on line 32
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 4 in e:\domains\s\stuff4web.co.uk\user\htdocs\flash-catalogue.php on line 33
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 4 in e:\domains\s\stuff4web.co.uk\user\htdocs\flash-catalogue.php on line 34
I have got it to work by changing $i = 0 to $i = 0.5 but this solution seems kinda dodgy
Please help me!