Jump to content

More than 1 row to echo out?


zelig

Recommended Posts

For some reason, I can only get 1 row to echo out when there are actually multiple rows in the database that should be echoing.

 

Here is what I have:

 

	$result = mysql_query("SELECT * FROM boards WHERE boardname='$board' ORDER BY id LIMIT 10");
	$post = mysql_fetch_assoc($result);
	echo stripslashes($post['message']) . "<br>\n" . " --- ".stripslashes($post['username']). " on ".stripslashes($post['time']) ."\n<hr width=90%>\n";

 

It pulls the one record great, but it only shows one record... I want to keep it to 10 records, thus the LIMIT in there (which I think I did right...), but it won't even show the ones in there right now (under 10, so that's not an issue yet).

Link to comment
Share on other sites

Hmm... I tried doing a loop, but I have to confess, I'm not overly familiar with them.

 

I got an error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

 

Here is the code I have now:

 

result = mysql_query("SELECT * FROM boards WHERE boardname='$board' ORDER BY id LIMIT 10");
	$post = mysql_fetch_assoc($result);
	while ($row = mysql_fetch_assoc($post)){
	echo stripslashes($row['message']) . "<br>\n" . " --- ".stripslashes($row['username']). " on ".stripslashes($row['time']) ."\n<hr width=90%>\n";}

 

What did I do wrong, so I can learn from it?

Link to comment
Share on other sites

try

$query = "SELECT * FROM boards WHERE boardname = '$board' ORDER BY id LIMIT 10";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
  echo stripslashes($row['message']) . "<br>" . " --- ".stripslashes($row['username']). " on ".stripslashes($row['time']) ."<hr width=90%>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.