Number of Members

Discussion in 'Software' started by Yzaraf, Aug 29, 2005.

  1. Yzaraf

    Yzaraf Private E-2

    Site Directory:
    C:\

    Files
    C:\index.html
    C:\forums\index.php (phpBB)

    On my index, I want to be able to show the total number of members on my forums. How could I do this?
     
  2. Coco

    Coco Sergeant Major

    You'd have to change the index to something that supports a scripting language. Most likely php. Once you've done that simply open a database connection (in the index.php file) and draw the number of users and echo it out. If you get stuck you could simply steal the code for it directly from phpbb, since phpbb actually displays this itself.
     
  3. Yzaraf

    Yzaraf Private E-2

    What function should I use to get the data from MySQL?
     
  4. Coco

    Coco Sergeant Major

    You need to create a connection then once connected draw the information. All of this is being done already in phpbb though, which is why I suggest taking the code form there.

    Although if you want, here is some simple code for creating a connection.
    Code:
    $this->dbHandle = mysql_connect("127.0.0.1", "username", "password")
    	or die("Fatal error: Could not connect to database!");
    mysql_select_db("databasename")
    	or die("Could not enter database!");
    
    Once you're connected you can just run an sql query to get what you want.
     
  5. Yzaraf

    Yzaraf Private E-2

    I cannot find anything within PHP that I could actually use... The only thing is this %d...


    Anyway... I managed to connect to the database, and then run a query

    PHP:
    $link mysql_connect('localhost''site''');
    if (!
    $link) {
       die(
    'Could not connect: ' mysql_error());
    }
    mysql_select_db("site_forum")
        or die(
    "Could not enter database!");
    $result mysql_query('SELECT active_users FROM `phpbb_users` WHERE 1');
    if (!
    $result) {
       die(
    'Invalid query: ' mysql_error());
    }
    echo 
    $result;
    And it displays Resource id #3

    Why do I get this?

    And where is the the code from phpBB?
     
  6. Coco

    Coco Sergeant Major

    What's with your SQL statement? It's written funny that's for sure. single quotes in SQL are suppost to be used to indicate a text value. Not a field or table name. Also, I'm not even sure if WHERE 1 is valid and if it is I don't see what it would be doing.

    SELECT active_users FROM phpbb_users

    is how you should write it. Although I'm not sure how phpbb stores this information, odds are there are multiple rows and since you're looking for a count of people you should write something like

    SELECT count(active_users) FROM phpbb_users

    Although I'm just guessing there since I'm not quite sure what is stored in the tables. I'd suggest testing the query in an SQL editor first and make sure you've got that working.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds