Jump to content

[SOLVED] Putting <br> after each record?


DootThaLoop

Recommended Posts

I'm kind of new to PHP. So this has been puzzling me. I am trying to make a script to display users online. So far, so good, but I need to know how to put spaces in between each users name on the row. Here is the error I get when I try to do that:

 

Parse error: syntax error, unexpected T_ECHO, expecting T_WHILE in /home/helloism/public_html/ynw/login/users.php on line 46

 

And here is the snippet of code I'm using. If you need to see more of or the entire code, let me know:

 

if (isset($row_online['username']))
{
do

echo ($row_online['username']."");

echo '<br>';

}

while($row_online = mysql_fetch_assoc($online));

 

I already know that this is the problem-causing line, so no big suprise:

 

echo '<br>';

 

So I need help... can I somehow put both echos together, or what? Thanks for looking!

Link to comment
https://forums.phpfreaks.com/topic/105671-solved-putting-ltbrgt-after-each-record/
Share on other sites

Hey there doot,

I'm also new to php. I haven't yet used a do while loop in php but have in java/c++. I might be totally wrong but shouldn't the closing curly brace of the if statement be after the while statement? like:

 

 

if (isset($row_online['username']))
{
    do
    {
        echo ($row_online['username']."");
        echo '<br>';
     }
    while($row_online = mysql_fetch_assoc($online));
}

 

 

hope that helps

~ Jazz

Jazz is correct but as your using mysql_fetch_assoc, you want the while without the do, as if no records are found your get errors

 

 

<?php
if (isset($row_online['username']))
{
while($row_online = mysql_fetch_assoc($online))
{
	echo ($row_online['username']."");
	echo '<br>';
}
}
?>

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.