View Single Post
Old 12-04-2006, 08:00 AM   #1 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
Question MySQL Is Going Mad!

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!

Last edited by markster; 12-04-2006 at 08:02 AM. Reason: Forgot to add part of information
markster is offline   Reply With Quote