Showing VIP members from db...

Status
Not open for further replies.
Jan 17, 2012
649
166
Hello,

I've been trying to figure out how to code a script that will get all the user's names from the database, and output then into the container. This is what I have so far;

PHP:
public static function getVipList()
        {
            global $db;
            $users = $db->query("SELECT username FROM users WHERE rank = 2 ORDER BY id");
            while($user = $users->fetch_assoc())
            {
                $get = $user['username'];
                return ($putcomma = implode(", ", (array)$get));
            }
        }
I want it to return a comma for every user, but it only shows this, even when I have more than one VIP user;


I want it to be something like this;


Any help?
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
PHP:
$get = $user['username'] . ', ';
Remove the implode etc. and just return that.

EDIT: And I'm not sure if you can return a while...
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
It doesn't output anything, the old code outputs only 1 username.
I guess you changed it wrong. Anyways, you might want to take a look at this: stackoverflow.com/questions/10728816/populate-array-from-while-loop-to-return-php

As you can not return a while.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,399
962
PHP:
public static function getVipList()
        {
            global $db;
            $users = $db->query("SELECT username FROM users WHERE rank = 2 ORDER BY id");
            while($user = $users->fetch_assoc())
            {
                $get = $user['username'];
                return implode(', ', $get);
            }
        }
dunno why you were casting $get as an array when it already is one
 

Kaz

BooYah
Staff member
Nov 16, 2010
3,064
1,025
This is what i do, i have changed to use your query but it works fine for me as im using mine for 'last online members'

PHP:
<?php
 
      $getVIPuser = $db->query("SELECT username FROM users WHERE rank = 2 ORDER BY id");
 
      while($vipUsers = $db->fetch_array($getVIPuser))  {
 
      echo "".$vipUsers['username'].", ";
 
        } 
?>

You may need to modify the code slightly, but it does work as im using the same code except for the mysql query
 
Status
Not open for further replies.

Users who are viewing this thread

Top