PHP Help Needed - Echoing Multiple MySQL Rows

Hi. The title sort of says it all.

I have a comment system, and entering comments works well, just echoing them out doesn’t work so great. I get “Resource id #5” and it gets…well, that’s not the comment. I found out that I need to use loops or mysql_result to echo multiple rows.

Is this so? How? I’m not so great at learning loops like “while($variable = $mysql)” and that kind of shazam.

Thanks in advance

There’s no magic involved and just about any thread in here could answer that question. If its just one record, you don’t need a loop, it would be something like:
[php]
$qry = mysql_query(“SELECT * FROM table WHERE column = value”);

$row = mysql_fetch_assoc($qry);

echo $row[‘id’]."
";
[/php]
if its more than 1 record, then it would be something like
[php]
$qry = mysql_query(“SELECT * FROM table WHERE column = value”);
// or $qry = mysql_query(“SELECT * FROM table”);

while($row = mysql_fetch_array($qry)) {
echo $row[‘id’]."
";
}
[/php]

of course, what kind of loop you use all depends on what you’re doing. you could use a for or a foreach loop to accomplish the same thing.

Sponsor our Newsletter | Privacy Policy | Terms of Service