Jump to content

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>';
}
}
?>

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.