Results 1 to 7 of 7

Thread: view active users(show admin different colour from users)

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Question view active users(show admin different colour from users)

    i have recently created a 'members list' which shows all registered users, and highlights admin in blue.

    here is memberslist.php:
    PHP Code:
    <?
    include("include/session.php");
    ?>
    <?php
    //process.php
    $host="mysql4.freehostia.com";
    $username="liaall_users";
    $password="********";
    $db_name="liaall_users";
    $tbl_name="users";

    mysql_connect("$host""$username""$password")or die("cannot connect to server");
    mysql_select_db("$db_name")or die("cannot select db");
    $query mysql_query("SELECT * FROM `users` ORDER BY username ASC,username") or die(mysql_error());
    ?>

    ****HTML HERE****

    <?php
    while($rows=mysql_fetch_array($query)){
    ?>
          <tr>
            <td align="center">
    <?php 
    if($rows['userlevel']=='9'){
       echo 
    '<a href="http://www.shiftysplayground.co.cc/userinfo.php?user='.$rows['username'].'"><font color="blue">'.$rows['username'].'</font></a>';
      }
    else{
       echo 
    '<a href="http://www.shiftysplayground.co.cc/userinfo.php?user='.$rows['username'].'">'.$rows['username'].'</a>';
    }
    ?>
    </td>
            </tr>
          <?php
    }
    ?>

    ****HTML HERE****
    i wanted to achieve the same thing with 'view_active.php', which is a different setup from 'memberslist.php'. in order to do this i would need to retrieve data from 2 seperate tables.(select all from table 'active users' and userlevel from table 'users')

    here is view_active.php:
    PHP Code:
    <?

    $q 
    "SELECT username FROM ".TBL_ACTIVE_USERS
        
    ." ORDER BY username ASC,username";
    $result $database->query($q);
    /* Error occurred, return given name by default */
    $num_rows mysql_numrows($result);
    if(!
    $result || ($num_rows 0)){
       echo 
    "Error displaying info";
    }
    else if(
    $num_rows 0){
       
    /* Display active users, with link to their info */
       
    echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
       echo 
    "<tr><td><font size=\"2\">\n";
       for(
    $i=0$i<$num_rows$i++){
          
    $uname mysql_result($result,$i,"username");

          echo 
    "<a href=\"userinfo.php?user=$uname\">$uname</a> | ";
       }
       echo 
    "</font></td></tr></table><br>\n";
    }
    ?>
    can anyone help me? your help would be very appreciated! thanx
    Last edited by liamallan; 04-06-2010 at 10:55 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    While it might be possible to get the combined result from MySQL using a very complex query, the general method for this is:
    1. Get all active users.
    2. Loop through each user:
    3. For each user, do a new query and loop up user level, etc.

    An outline:
    $q = mysql_query('FIND ACTIVE USERS');
    foreach ($activeusers as $activeuser) {
    $q = mysql_query('FIND USER INFO WHERE `user` = $activeuser;');
    }

    Of course that's not functional code, but the method should be easy enough to integrate into your system.

    Hope that helps.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    thanx for the reply!!

    i have tried what u said but cant seem to get it to work. tried allsorts, problem is, i undone all my work and put the original view_active.php buck up on the server so i have lost it all, to show u where i was.

    when i try, it either tells me 'error displaying info' or the page is extremely offset.

  4. #4
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    i been trying to connect to both databases, but anything i try, doesnt work. can anyone show me an example to how i could connect to mutliple databases? any help really appreciated

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Are you actually using multiple databases? Why? Or do you mean multiple tables?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    sorry, its multiple tables. ('active_users' and 'users')

  7. #7
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    i been playing about with view_active.php, and here is wot i got now:
    PHP Code:
    <?
    $host
    ="mysql4.freehostia.com";
    $username="liaall_users";
    $password="*********";
    $db_name="liaall_users";
    $tbl_name="users";

    mysql_connect("$host""$username""$password")or die("cannot connect to server");
    mysql_select_db("$db_name")or die("cannot select db");
    $query mysql_query("SELECT * FROM `users` ORDER BY username ASC,username") or die(mysql_error());

    $q "SELECT username FROM ".TBL_ACTIVE_USERS
        
    ." ORDER BY username ASC,username";
    $result $database->query($q);
    /* Error occurred, return given name by default */
    $num_rows mysql_numrows($result);
    if(!
    $result || ($num_rows 0)){
       echo 
    "Error displaying info";
    }
    else if(
    $num_rows 0){
       
    /* Display active users, with link to their info */
       
    echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
       echo 
    "<tr><td><font size=\"2\">\n";
       for(
    $i=0$i<$num_rows$i++){
          
    $uname mysql_result($result,$i,"username");
       }
    while(
    $rows=mysql_fetch_array($query)){
    }
    if(
    $rows['userlevel']=='9'){
       echo 
    "<a href=\"http://www.shiftysplayground.co.cc/userinfo.php?user=$uname\"><font color=\"blue\">$uname</font></a>";
      }
    else{
       echo 
    "<a href=\"userinfo.php?user=$uname\">$uname</a> | ";
       }
       echo 
    "</font></td></tr></table><br>\n";
    }
    ?>
    made a small advance since the last time, which wouldnt display due to something being wrong in the coding, but now it displays the page. although, usernames with 'userlevel' value of 9, arent displayed in blue!

    any ideas?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •