vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Proper Comma Construction? (https://vborg.vbsupport.ru/showthread.php?t=71222)

kaotic 10-31-2004 10:42 PM

Proper Comma Construction?
 
Here's the code that I'm working with:

Code:

$GetUser = $DB_site->query("select s.*,u.* from ".TABLE_PREFIX."session s
left join ".TABLE_PREFIX."user u on (u.userid = s.userid) where s.location like '%test.php%'");
        while($UserIN = $DB_site->fetch_array($GetUser)){
        if(!$store_c[$UserIN['userid']]){
                if($UserIN['userid']){
                $activeusers .= "<a href='member.php?u={$UserIN['userid']}'>{$UserIN['username']}</a>, ";
                }
        }
}

I'm using it to contruct a users online list, but I'm having a problem with comma placements. Using the code above, a comma is placed once after each users name, including the last one to be listed... so it ends up looking like:

Quote:

user1, user2, user3,
Can anyone help me rid myself of the final comma? Assistance would be most appreciated.

filburt1 10-31-2004 10:58 PM

Add everything to an array in the loop, then use implode(", ", $arrays_name) to add the commas.

I also wrote an English sentence comma delimiter in Java it if helps (operates on an array of Objects).

kaotic 10-31-2004 11:15 PM

Ehh... I apologize for my ignorance, but I'm not very familiar with PHP. Could you further elaborate?

filburt1 10-31-2004 11:19 PM

PHP Code:

$users = array();

$GetUser $DB_site->query("select s.*,u.* from ".TABLE_PREFIX."session s
left join "
.TABLE_PREFIX."user u on (u.userid = s.userid) where s.location like '%test.php%'");
    while(
$UserIN $DB_site->fetch_array($GetUser)){
    if(!
$store_c[$UserIN['userid']]){
        if(
$UserIN['userid']){
        
array_push($users"<a href='member.php?u={$UserIN['userid']}'>{$UserIN['username']}</a>");
        }
    }
}

$activeusers implode(", "$activeusers); 

edit: BTW, you badly need to add more whitespace to your code...it is very hard to read with it all scrunched together.

kaotic 10-31-2004 11:35 PM

Aye! Well, thank you for that. I appreciate the assistance. :)


All times are GMT. The time now is 07:05 AM.

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.01044 seconds
  • Memory Usage 1,723KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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