vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   need if conditional.... (https://vborg.vbsupport.ru/showthread.php?t=77575)

indie 03-06-2005 06:43 AM

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

Scrub 03-06-2005 07:28 AM

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?

indie 03-06-2005 07:46 PM

No, this caused the page to be just a white page. Code error somewhere.

Link14716 03-06-2005 07:58 PM

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>";



why-not 03-06-2005 08:17 PM

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!

indie 03-06-2005 09:11 PM

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

Link14716 03-07-2005 09:10 PM

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.


All times are GMT. The time now is 08:51 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01080 seconds
  • Memory Usage 1,791KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete