Jump to content

While Loop (display all data in a column)


markvaughn2006

Recommended Posts

I know this is simple, but all the while loop examples show you how to count to ten and then stop looping when it is greater than 10.

I just need a while loop to display all data in a column and stop when it gets to the bottom.

This is my jacked up attempt to display all usernames in the user_name column. Also how would I go about putting a <br> in between each echo? Thanks much!

 

$result = mysql_query("SELECT user_name FROM users_tbl'") or die(mysql_error()); 

while $row = mysql_fetch_array( $result );

 

echo $row['user_name'];

Link to comment
https://forums.phpfreaks.com/topic/174256-while-loop-display-all-data-in-a-column/
Share on other sites

Hi

 

Assuming you mean one username per row (rather than a row having multiple user names which you want to split up):-

 

$result = mysql_query("SELECT user_name FROM users_tbl'") or die(mysql_error());  
while ($row = mysql_fetch_array( $result ))
{
echo $row['user_name'].'<br />';
}

 

All the best

 

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.