Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-06-2005, 06:43 AM
indie indie is offline
 
Join Date: Aug 2004
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default need if conditional....

For this chat script, I need an if conditional so when there are no names to display, it says "No members in Chat".

Also, if you can figure out how to use the usergroup html markup for usernames (ex: like bold names for usergroups that have bold names in online box) that would be great.

---------------------------------------------
function usersinroom( $room = "" )
{
$cms = $GLOBALS['fc_config']['cms'];
$list = array();

if($room) {
$stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND roomid=?");
$rs = $stmt->process($room);
} else {
$stmt = new Statement("SELECT userid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL");
$rs = $stmt->process();
}

while($rec = $rs->next()) $list[] = array_merge($cms->getUser($rec['userid']), $rec);

return $list;
}

-------------------
then is says:
-------------------

$users = usersinroom();
$arr = array();
foreach( $users as $user ) {
echo "<a href=\"member.php?userid=$user[userid]\">$user[login]</a>";
}

=========================
thanks
Reply With Quote
  #2  
Old 03-06-2005, 07:28 AM
Scrub's Avatar
Scrub Scrub is offline
 
Join Date: Oct 2001
Posts: 188
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Change
PHP Code:
$users usersinroom();
$arr = array();
foreach( 
$users as $user ) {
echo 
"<a href=\"member.php?userid=$user[userid]\">$user[login]</a>";

To
PHP Code:
$users usersinroom();
$arr = array();
foreach( 
$users as $user ) {
echo 
"<a href=\"member.php?userid=$user[userid]\">$user[login]</a>";
} else {
echo 
"<b>No Members in Chat</b>";

I belive that should work?
Reply With Quote
  #3  
Old 03-06-2005, 07:46 PM
indie indie is offline
 
Join Date: Aug 2004
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, this caused the page to be just a white page. Code error somewhere.
Reply With Quote
  #4  
Old 03-06-2005, 07:58 PM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

foreach is a loop, not a conditional. Therefore:

PHP Code:
$users usersinroom();
$arr = array();
if (!empty(
$users)) {
    foreach (
$users as $user) {
        echo 
"<a href=\"member.php?userid=$user[userid]\">$user[login]</a>";
    }
} else {
    echo 
"<b>No Members in Chat</b>";

Reply With Quote
  #5  
Old 03-06-2005, 08:17 PM
why-not why-not is offline
 
Join Date: Feb 2004
Posts: 218
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi

You should really be checking if the query returns any thing, there is no sense doing a while() loop on a null returned result set! Also it would be better to do the link building inside the usersinoom() function and just return the links or if no users are in the room, just return "No Users In Room". It wasted coding to do (2) loops and if()s when you don't have to! Logic is missing from this!!!

Show me or tell me the database class you are using, and I will writre you how to do it the right way! I need to know the DB class to see if it has a function that returns the row count for the query!

Sonia!
Reply With Quote
  #6  
Old 03-06-2005, 09:11 PM
indie indie is offline
 
Join Date: Aug 2004
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks if you can help. Here's the whole page. PS - I'm also trying to see if it's possible to add the html markup, like if usernames are bold, etc. Thanks

PHP Code:
<?php

    header
("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
    
header("Cache-Control: no-store, no-cache, must-revalidate");
    
header("Cache-Control: post-check=0, pre-check=0"false);
    
header("Pragma: no-cache");


/**
If this file is not in the FlashChat root folder, then change this
path to the location of the inc/common.php file.
*/
include_once('inc/common.php');

ChatServer::purgeExpired();

/**
Retrieves the number of users who are chatting in any room.
Leave the $room parameter empty to return the number of users in all room.
*/
function numusers$room "" )
{
    if(
$room) {
        
$stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND roomid=?");
        
$rs $stmt->process($room);
    } else {
        
$stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL");
        
$rs $stmt->process();
    }

    
$rec $rs->next();

    return 
$rec?$rec['numb']:0;
}

/**
Retrieves a list of the users (by login ID) who are in $room.
Leave the $room parameter empty to return a list of all users in all rooms.
*/
function usersinroom$room "" )
{
    
$cms $GLOBALS['fc_config']['cms'];
    
$list = array();

    if(
$room) {
        
$stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND roomid=?");
        
$rs $stmt->process($room);
    } else {
        
$stmt = new Statement("SELECT userid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL");
        
$rs $stmt->process();
    }

    while(
$rec $rs->next()) $list[] = array_merge($cms->getUser($rec['userid']), $rec);

    return 
$list;
}

/**
Retrieves a list of all available rooms, as an array.
*/
function roomlist()
{
    
$list = array();

    
// populate $list with the names of all available rooms
    
$stmt = new Statement("SELECT * FROM {$GLOBALS['fc_config']['db']['pref']}rooms WHERE ispublic IS NOT NULL");
    
$rs $stmt->process();

    while(
$rec $rs->next()) $list[] = $rec;

    
//result will be an array of arrays like ('id' => <room id>, 'updated' = <timestamp>, 'created' => <timestamp>, 'name' => <room name>, 'ispublic' => <public flag>, 'ispermanent' => <autoclose flag>)
    
return $list;
}


$rooms roomlist();
$roomnumb sizeof($rooms);
?>

<?php if($roomnumb) { ?>
        <table border="0" cellpadding="1">
        
            
                <tr>

                    <td><div class="smallfont"><?php

                        $users 
usersinroom();
                                    
$arr = array();
                        foreach( 
$users as $user ) {
                             echo 
"<a href=\"member.php?userid=$user[userid]\">$user[login]</a>";
                        }
          
$lis implode(", "$arr); 
          echo 
$lis;

                    
?> </div></td>
                </tr>
                
        </table>
<?php ?>









Added to post:



Quote:
Originally Posted by Link14716
foreach is a loop, not a conditional. Therefore:

PHP Code:
$users usersinroom();
$arr = array();
if (!empty(
$users)) {
    foreach (
$users as $user) {
        echo 
"<a href=\"member.php?userid=$user[userid]\">$user[login]</a>";
    }
} else {
    echo 
"<b>No Members in Chat</b>";

Thanks, I used this and it works fine!

Anyone know how to add the html markups to the usernames? Like, if a name is bolded, it can show the bolded names in the who's chatting, so it matches the who's online?

Thanks!

Also, I didn't post the whole code before, so can you tell me if what you gave me as the fix is correct?

PHP Code:
<tr>

                    <td><div class="smallfont"><?php

                        $users 
usersinroom();
                        
$arr = array();
                        if (!empty(
$users)) {
                            foreach (
$users as $user) {
                            echo 
"<a href=\"member.php?userid=$user[userid]\">$user[login]</a>";
                                               }
                        } else {
                            echo 
"<em>Chat is empty.</em>";
                        } 
          
$lis implode(", "$arr); 
          echo 
$lis;

                    
?> </div></td>
                </tr>
Since I didn't give you the $lis part before, I want to make sure what you gave me is lined up properly.





thanks
Reply With Quote
  #7  
Old 03-07-2005, 09:10 PM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The usergroup markup requires global.php from vBulletin to be included and then it is a function. I forgot the name of the function, though. I know it contains 'musername' and it in includes/functions.php, though.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:31 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08141 seconds
  • Memory Usage 2,279KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete