SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot cdndesignz's Avatar
    Join Date
    Dec 2004
    Location
    Winnipeg
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A lil PHP help pls... :-) display usernames?

    I ALMOST have this figured out, but it's not quite showing what I want it to show and I'm not a "real" PHP programmer.... can anyone finish what I started here?

    In PHP Nuke 7.8, on the Admin.php page, in the Who's Online box, I want it to show the numbers of Online, number of new today etc. like it has already. Then I want it to ALSO display the usernames of those currently logged in. (Post Nuke has this function.. the PHPBB Forums has this function, but PHP Nuke didn't come with it ... so... a little tweaking! ) I found one thread about doing this on the support site, but it didn't contain the code just said someone figured it out.

    Approx line #350 of Admin.php:


    OpenTable();
    $guest_online_num = $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='1'"));
    $member_online_num = $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'"));
    $who_online_num = $guest_online_num + $member_online_num;
    $who_online = "<center><font class=\"option\">"._WHOSONLINE."</font><br><br><font class=\"content\">"._CURRENTLY." $guest_online_num "._GUESTS." $member_online_num "._MEMBERS."<br>";
    $row3 = $db->sql_fetchrow($db->sql_query("SELECT COUNT(user_id) AS userCount from $user_prefix"._users." WHERE user_regdate LIKE '$curDate2'"));
    $userCount = $row3['userCount'];
    $row4 = $db->sql_fetchrow($db->sql_query("SELECT COUNT(user_id) AS userCount FROM $user_prefix"._users." WHERE user_regdate LIKE '$curDateP'"));
    $userCount2 = $row4['userCount'];
    $who_online_users = $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'"));
    echo "<center>$who_online<br>"
    .""._BTD.": <b>$userCount</b> - "._BYD.": <b>$userCount2</b></center>";
    echo "<center>$who_online_users<br>"
    .""._BTD.": <b>$who_online_users</b> - "._BYD.": <b>$who_online_users2</b></center>";

    CloseTable();
    The italics are my attempt at making this work. Alas didn't test out (on the bright side didn't cause white screen of death, just didn't display the right thing it displayed the numbers again not the usernames.

    I THINK I'm creating and calling the right function... but the echo statement is what's wrong I'm pretty sure. Don't have time for the entire PHP Programming 101 and 202 courses tonight... someone who codes in their sleep can probably fix this in 30 seconds and it will then be available to everyone right?? Smile

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    hi, from what I can tell from your code this line:
    PHP Code:
    $who_online_users $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'")); 
    is querying the database for the number of rows returned from the query.....

    My guess is that if you change it to:
    PHP Code:
    $who_online_users $db->sql_fetchrow($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'")); 
    Worth a try....

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Zealot cdndesignz's Avatar
    Join Date
    Dec 2004
    Location
    Winnipeg
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Spike,
    Great thanks... duh that makes sense... Does the "echo" statement corresponding to the username output make sense?? I was rather shaky on that part of it, just duplicated and modified the output statement from the numbers...

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    yes, except this variable
    PHP Code:
    $who_online_users2 
    because it's not actually set anywhere!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Zealot cdndesignz's Avatar
    Join Date
    Dec 2004
    Location
    Winnipeg
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm ok.. it did that in the output of the numbers and I thought thats what made it do number1, then number 2, then number 3 etc. How do I get the usernames to display in some sort of alphabetical order with spaces in between, or any order for that matter?

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Not knowing your class setup my best guess would be:
    PHP Code:

    OpenTable
    ();
    $guest_online_num $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='1'"));
    $member_online_num $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'"));
    $who_online_num $guest_online_num $member_online_num;
    $who_online "<center><font class=\"option\">"._WHOSONLINE."</font><br><br><font class=\"content\">"._CURRENTLY.$guest_online_num "._GUESTS.$member_online_num "._MEMBERS."<br>";
    $row3 $db->sql_fetchrow($db->sql_query("SELECT COUNT(user_id) AS userCount from $user_prefix"._users." WHERE user_regdate LIKE '$curDate2'"));
    $userCount $row3['userCount'];
    $row4 $db->sql_fetchrow($db->sql_query("SELECT COUNT(user_id) AS userCount FROM $user_prefix"._users." WHERE user_regdate LIKE '$curDateP'"));
    $userCount2 $row4['userCount'];
    $who_online_users $db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'");
    echo 
    "<center>$who_online<br>"
    .""._BTD.": <b>$userCount</b> - "._BYD.": <b>$userCount2</b></center>";

    echo 
    "<center>$who_online_users<br>"
    .""._BTD.": <b>$who_online_users</b> - "._BYD.": <b>";
    while(
    $rows $db->sql_fetchrow($who_online_users)) {
        echo 
    $rows[0] .'<br />';
    }
    echo 
    "</b></center>";
    CloseTable(); 
    Using a while loop to return all the users online.....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Zealot cdndesignz's Avatar
    Join Date
    Dec 2004
    Location
    Winnipeg
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow sweet Spike.. thank you very much ... I will test this and see if it works or if I can get it to work today...I'll let you know! I knew it was a quick thing for someone who "thinks" in PHP.. I can follow it well by now from customizing all the stuff in PHPNuke but I don't have the syntax down to WRITE it yet...

  8. #8
    SitePoint Zealot cdndesignz's Avatar
    Join Date
    Dec 2004
    Location
    Winnipeg
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Spike,
    Hmm OK I'm back...


    Here is current code where I'm at:

    PHP Code:
    OpenTable();
        
    $guest_online_num $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='1'"));
        
    $member_online_num $db->sql_numrows($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'"));
        
    $who_online_users $db->sql_fetchrow($db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest='0'")); 
        
    $who_online "<center><font class=\"option\">"._WHOSONLINE."</font><br><br><font class=\"content\">"._CURRENTLY.$guest_online_num "._GUESTS.$member_online_num "._MEMBERS."<br>";
        
    $row3 $db->sql_fetchrow($db->sql_query("SELECT COUNT(user_id) AS userCount from $user_prefix"._users." WHERE user_regdate LIKE '$curDate2'"));
        
    $userCount $row3['userCount'];
        
    $row4 $db->sql_fetchrow($db->sql_query("SELECT COUNT(user_id) AS userCount FROM $user_prefix"._users." WHERE user_regdate LIKE '$curDateP'"));
        
    $userCount2 $row4['userCount'];
            
      echo 
    "<center>$who_online<br>"
            
    .""._BTD.": <b>$userCount</b> - "._BYD.": <b>$userCount2</b></center>";

    echo 
    "<center>$who_online_users<br>"
    ."Users currently online: <b>$who_online_users</b>";
    while(
    $rows $db->sql_fetchrow($who_online_users)) {
        echo 
    $rows[0] .'<br />';
    }
    echo 
    "</b></center>";        
        
    CloseTable(); 
    And here is the display it is giving me:

    Who's Online

    There are currently, 22 guest(s) and 11 member(s) that are online.

    New Today: 2 - New Yesterday: 3
    Array
    Users currently online: Array
    Obviously it's identified it's looking for an array, but it's not outputting the results. Once more with feeling...

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    well we are getting there!

    ok, try:
    PHP Code:
    while($rows $db->sql_fetchassoc($who_online_users)) {
        echo 
    $rows['uname'] .'<br />';

    assuming that there is a function defined that uses mysql_fetch_assoc....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Zealot cdndesignz's Avatar
    Join Date
    Dec 2004
    Location
    Winnipeg
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK.. unfortunately it had a hairball on that one.... grudgingly spit out same output with "Array" as above and then dead-ended every other function and output on the page after that. Slight indigestion...

    I looked for other outputs after sql queries, but the other ones all output into generated tables and become pretty complex, like "find last 20 articles, create a table and a row for each story, order them by formatted timestamp and include admin function buttons after each one".. way more complex.

    This is PHP-Nuke 7.8, SQL 5.0, and PHP4.1+ if that helps you any... what standard PHP function turns an array into a list of items?


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
  •