Page 1 of 1

question about rows

Posted: Wed Jul 17, 2002 7:45 am
by richieio
ok I am new with php and mysql so dont hang me :D

I'm trying to fetch some rows here using:

while ($row = $result->mysql_fetch_row()){
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td></tr>\n";
}

and i get this!

Fatal error: Call to undefined function: mysql_fetch_row() in /usr/local/apache/htdocs/admin_add.php on line 74

thats line 74 up there.

whats goin on here? please help, i just installed apache w/php & mysql and i'm trying to learn.

Thx,

Posted: Wed Jul 17, 2002 8:01 am
by llimllib

Code: Select all

while($row = mysql_fetch_row($result)) &#123;
    echo "...";
&#125;
You were getting an error because the '->' notation selects a method that belongs to an object. In other words, you were trying to call the 'mysql_fetch_row' method of object $result - except $result is not an object. Do a print_r($result) and you'll see that it's only an integer. So, PHP tried to find the mysql_fetch_row method *inside* $result, which failed. Instead, you want to call the mysql_fetch_row method and supply the argument, as listed above.

Posted: Wed Jul 17, 2002 8:45 am
by richieio
awesome, thanks for the quick reply.

Ok i just tried it and i got this warning:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /usr/local/apache/htdocs/admin_add.php on line 74

:(

Is there somewhere i can go that will tell me what this stuff means so i dont have to come ask you guys everytime something wrong happens :D

Thx!

Posted: Wed Jul 17, 2002 8:51 am
by twigletmac
That error probably means that there is a problem with your query try doing the following:

Code: Select all

$sql = "SELECT whatever FROM yourtable WHERE somestuff";
$result = mysql_query($sql) or die(mysql_error().'<br />'.$sql);
Mac