noob php & MySQL help

Joined
Mar 19, 2008
Messages
143
Reaction score
13
hello im currently making a script for my site

here it is:
PHP:
<?php $lang->addLocale("widget.recommended"); ?>
<div class="habblet-container ">        
                        <div class="cbb clearfix blue ">
    <h2 class="title"><b><i>Online Users:</b></i></h2>
    <div id="promogroups-habblet-list-container" class="habblet-list-container groups-list">
<center>
</br>
<?php
$page['id'] = "community";
echo '<b>The following users are currently online:</b>';

$getUsers = mysql_query("SELECT id,name FROM cms_users WHERE show_online = '1' ORDER BY id ASC");
$getRank = mysql_query("SELECT rank FROM users ORDER BY id ASC");

if($getRank['rank'] == "7")
{
echo '<span style="font-weight:bold;color:#339966;background: url(http://forum.ragezone.com/images/backround9.gif)">';
}
   
echo '<ul style="margin: 0; color:#000000">';
if(mysql_num_rows($getUsers)) 

{
  while ($u = mysql_fetch_assoc($getUsers))
{


        echo " ".$getUsers['name'].($u['name']);" ";   


  echo ', ';
    }
    
    echo '</ul>';
    echo '</span> ';

}


?>

</div>
    
                        
                    </div>
                </div>
                <script type="text/javascript">if (!$(document.body).hasClassName('process-template')) { Rounder.init(); }</script>


this shows a list of users online, but i want to separate the users from the admins&mods is there anything i could use to do this i thought an IF query would do, but as im just starting out in php and SQL i don't know any other methods or how to do it properly.
 
Last edited:
Well then the admins & mods ranks would have to be different. You're starting it off right by doing the
PHP:
if($getRank['rank'] == "7"){}

So then just keep doing an if/else, for the admins and then another for the mods, I guess, if you're trying to split them up like you said. But if the ranking goes in chronological order from Admin -> user you could just display the ranks by the order of them, if that makes sense..
 
You can order by the ranks in MySQL if there's a field that has their rank in cms_user. Why do you have two tables: users and cms_user?

If you had the rank field in cms_user you could sort by the rank, put a special icon or background img/color for different ranks, etc. It would be much easier. Also, do you have the rank names available? or are they all numbers..?

You'll need to attach the rank id with the rank name at some point to display the ranks. I wouldn't use many conditional statements for this, I'd just order them, have an array with an identifier for each rank (bg color/ icon), and display them all in the same data-table.
 
The table user hold rank,name,email,id, ect. the table cms_user holds if the user is online,

---------- Post added at 06:54 PM ---------- Previous post was at 06:53 PM ----------

Quote: If you had the rank field in cms_user you could sort by the rank, put a special icon or background img/color for different ranks, etc. It would be much easier. Also, do you have the rank names available? or are they all numbers..?, There all numbers 3-7.
 
Code:
SELECT. * FROM table WHERE rank != 'admin'

or...

Code:
SELECT. * FROM table JOIN ranks ON users.fk_rank=ranks.rank HAVING ranks.rank_name = 'user'

etc. This assumes the structure of the tables, but you can easily separate these with queries. As stated above, if you're wanting to display them all but separate them, get everything (order by rank) and split them with a little logic in your code.
 
Last edited:
Back