mysql_fetch_array error
I've got a problem, I have many scripts that use this syntax, but it doesn't work. I don't know why, it comes up with _fetch_array is not a valid argument...anybody see why?
<?php
...connection...
$sql = mysql_query(\"SELECT * FROM data\");
while ($qry = mysql_fetch_row($sql)) {
echo \"<p class=\\"title\\">$qry[header]<\/p>\";
echo \"<p> $qry[body]<\/p>\";
echo \"<p class=\\"line\\">---------------<\/p>\";
}
mysql_close($dbh);
?>
thanks
Suzanne posted this at 00:27 — 19th January 2004.
She has: 5,507 posts
Joined: Feb 2000
mysql_fetch_array?
kb posted this at 00:32 — 19th January 2004.
He has: 1,380 posts
Joined: Feb 2002
lol _fetch_row
sorry.
Suzanne posted this at 00:48 — 19th January 2004.
She has: 5,507 posts
Joined: Feb 2000
http://www.webmaster-forums.net/showthread.php?t=22762&highlight=mysql_fetch_row+mysql_fetch_array from the last time we talked about this, in case you need the reference.
I tend to code it differently, so you may be getting an error in something I can't see because I'm not familiar with it:
<?php
...connection...
$sql = mysql_query(\"SELECT * FROM data\");
// this *should* work, but I use mysql_fetch_array usually
while ($qry = mysql_fetch_row($sql)) {
$header = $qry[0];
$body = $qry[1];
echo<<<DISPLAY
<p class=\"title\">$header</p>
<p> $body</p>
<p class=\"line\">---------------</p>
DISPLAY;
}
mysql_close($dbh);
?>
In general, it looks fine, perhaps there is no data returned? Put in some error messages and see what you get?
ROB posted this at 05:08 — 19th January 2004.
They have: 447 posts
Joined: Oct 1999
also, even though I believe the php manual claims theres little performance difference, you should use mysql_fetch_assoc or mysql_fetch_row unless you specifically need both, because I've benchmarked them and mysql_fetch_array is significanlty slower.
druagord posted this at 15:04 — 19th January 2004.
He has: 335 posts
Joined: May 2003
with fetch_row you have to use $qry[0] $qry[1] with fetch_array you can use $qry['header'] and $qry['body']
ROB posted this at 04:50 — 20th January 2004.
They have: 447 posts
Joined: Oct 1999
fetch_row returns a number indexed array, fetch_assoc returns a string indexed hash, fetch_array returns both.
kb posted this at 16:42 — 19th January 2004.
He has: 1,380 posts
Joined: Feb 2002
Thanks, suzanne...
That's the script i was referring to, and didn't understand what was wrong
Suzanne posted this at 16:55 — 19th January 2004.
She has: 5,507 posts
Joined: Feb 2000
I thought it was something like that, Druagord, I've amended my code sample to accomodate that.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.