0

Hello, since i am new to the forum please excuse me if the topic is not in the correct section. I would like to ask how to do the next thing i mean when you have a limit on who is online and who does not say 30 users are online and when they become 31 to stop there to list users, while the bottom where $numb of Online users ($numb) continues to display more and more online users ... I hope you understand me what i mean :)

<div class="menu">
                  <div class="value">
                            <?
                            $time = time()-3*60;
                            $user = $logged['username'];
                            $query = mysql_query("UPDATE users SET status = '$time' WHERE username='$user'") or die (mysql_error());
                            $query1 = mysql_query("SELECT * FROM users WHERE status >= '$time'") or die (mysql_error());
                            $broi = mysql_num_rows($query1);
                            if($broi == 0)
                            {
                                echo "<font color='red'><img src='templates/img/icons/user_offline.gif' /> No online users. </font><hr>";
                            }
                            else
                            {
                                $row = mysql_fetch_array($query1);
                                echo "<hr class='dash' /><div><b><a href='profile?user=$row[username]'>$row[username]</a></b> <span style='float:right; margin-right: 5px;'><img src='templates/img/icons/online.gif' /></span></div> <hr class='dash' />";
                            }
                            echo "Online total: <b>".$broi."</b>";

                            ?>
                  </div>Online users($numb)
              </div>
4
Contributors
9
Replies
10
Views
5 Years
Discussion Span
Last Post by diafol
0

Use the clause: LIMIT 30
at the end of your SQL string.

$query1 = mysql_query("SELECT * FROM users WHERE status >= '$time' LIMIT 30")

Edited by diafol: n/a

0

Yes, and i generally do so, but this limit 30 where he put in the sql query i put a limit on the number of users that will list them all but i want the bottom and Online users ($numb) i can still display them just below where the names have a limit ...

0

maybe somethin like this

else
{
for ( $i;$i <30 && $row = mysql_fetch_array($query1); $i++)
   {
   echo "<hr class='dash' /><div><b><a      
   href='profile?user=$row[username]'>$row[username]</a></b> <span  
   style='float:right; margin-right: 5px;'><img src='templates/img/icons/online.gif' /></span></div> <hr class='dash' />";
   }
}
echo "Online total: <b>".$broi."</b>";
0

If your traffic gets high, then I really advise you to take ardav's route with the limit, and query the table again for a count. If you don't, you will get an enormous performance breakdown, because you are allocating huge amounts of resources that never will be used.

0

Well then how women make the application in sql LIMIT 30 serve the same function and which pzuurveen

0

I don't understand what you need. If you need to limit a recordset to 30 use limit 30 as the db will stop retrieving after it finds 30 records. Using a loop to filter is wasteful and time consuming. Doesn't make much sense to me.

0

So i want to stop 30 results, but also to continue counting bottom $numb, is there such an option ?

0

Do a count call AND a limit call
Do a combined call (no limit) with counter loop

Time both approaches and see which one is fastest.
This pretty much depends on the number of records that you have. Large numbers, use LIMIT, else, I don't think it really matters.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.