MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 17th, 2003, 03:25 AM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
excluding the trailing comma from info retrieved via mysql... please help

hi--

this is driving me up the wall: i want to retrieve all of the usernames which are currently logged in (something like a users online script)...but i cannot get that darn trailing comma to go away. I've tried rtrim and all sorts of loops and whatnot. ive even tried ben's "who's online" script and integrated it with my users system, however, i can't get rid of it! please steer me in the right direction, as i'm completely lost here
__________________
-Alexander

Reply With Quote
  #2  
Old February 17th, 2003, 12:21 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
I created a simple function for this long ago. I have since integrated a more detailed version of it into a class module.

However, this should do the trick for your needs:
Just run your string through this command and off you go:


PHP Code:
function chop_last_char($str) {
    return 
substr($str,0,-1);

__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old February 17th, 2003, 02:37 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
hello laidbak,

thank you-- but now i'm getting two of the same result. so far i am in complete testing stage, there are two registered users...for privacies sake, we'll refer to them as "joe1" and "schmoe1"

well, when i use your function, the output i recieve is "Joe1, Joe1"

here is the code i am using: (ive based my db class on ben's m/a script)

PHP Code:
function GetCurrentAdmins () {
    
            
$dbVars = new dbVars();
            @
$svrConn mysql_connect($dbVars->strServer$dbVars->strUser$dbVars->strPass);

            if(
$svrConn)
                    {
                            
$dbConn mysql_select_db($dbVars->strDb$svrConn);

                            if(
$dbConn)
                                    {    
                                
                                    
$Query "SELECT username FROM users WHERE level = '4'";
                                    
// OR....  ORDER BY username DESC
                                    
$result mysql_query($Query);
                                    
                                    if (
$result) {
                                    
                                                while(
$row mysql_fetch_row($result)) {

                                                
$username  implode(', '$row);

                                                    
chop_last_char($username);
                                                    
                                                    echo 
$username;
                                                    
                                                }
                                                    
                                            } else {
                                        
                                            echo 
'No current administrators.';
                                    
                                        }
                                    
                                    } else {
                                    
                                    echo 
'Couldn\'t connect to database.';
                                    
                                    }
                                
                                } else {
                                
                                echo 
'Couldn\\'t connect to database.';
                                
                                }
                            
                            }
                            
    // END FUNC 


PS., for some reason, vBulletin wont let me escape my 's so bare that in mind, thank you

Reply With Quote
  #4  
Old February 17th, 2003, 03:42 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Your code is:

PHP Code:
while($row mysql_fetch_row($result)) {
  
$username  implode(', '$row);
  
chop_last_char($username);
  echo 
$username;



It should be:

PHP Code:
while ($row mysql_fetch_row($result)) {
  
$username[] = $row['username'];
}

  
$username =  implode(','$username);
  echo 
$username


Now you don't even need " chop_last_char($username);"

Last edited by laidbak : February 17th, 2003 at 03:45 PM.

Reply With Quote
  #5  
Old February 17th, 2003, 03:53 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
ahhh genius! thank you very much, im gonna have to start paying you for that function because its awesome eheh.. thank you again--

Reply With Quote
  #6  
Old February 17th, 2003, 04:08 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Hey,

No problem.
I'm glad to hear the solution solved your problem.

Happy Coding,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > excluding the trailing comma from info retrieved via mysql... please help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway