Putting member no live on website

Discussion in 'MySQL' started by digitalhaven, Aug 8, 2006.

  1. #1
    How do I put live membership figures on my site, I have mysql databases, any scripts I can get to do the job?
     
    digitalhaven, Aug 8, 2006 IP
  2. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #2
    I'm a little lost, please explain better.
     
    smatts9, Aug 8, 2006 IP
  3. digitalhaven

    digitalhaven Peon

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I know from my databases I have x members but how do I get that figure on my index page in something like "x members and growing" and have it updating every time I get a new member. Understand?
     
    digitalhaven, Aug 8, 2006 IP
  4. Colleen

    Colleen Illustrious Member

    Messages:
    6,777
    Likes Received:
    725
    Best Answers:
    1
    Trophy Points:
    430
    #4
    You just have to write up a query and put it in a php page, you'll need to know the table and column name in the database to do this.

    Here's a basic query tutorial: http://students.nebrwesleyan.edu/tutorial/php/page7.php

    If you need help, when I get back I can help you write it up, but I will need some info first.
     
    Colleen, Aug 9, 2006 IP
    Weirfire likes this.
  5. digitalhaven

    digitalhaven Peon

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for that info am justing trying to find where in the database to query. Thanks for that tut too. Now to see if I can get it working!
     
    digitalhaven, Aug 11, 2006 IP
  6. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You have several ways of doing this with simpel sql :

    Select max(UserID) from Users; if you are using auto_increment on Users this will work fine(if you remove a user it will not show the removed user

    Otherwise you can use

    select count(Username) from Users;

    This way you cound more actual number of users (if you remove users this will count the actual number of users)

    Hope this helps a bit
     
    ThomasNederman, Aug 12, 2006 IP
  7. digitalhaven

    digitalhaven Peon

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I can't get it to work, is the tut above accurate? Can someone post a example of working code (obviously with different variables to protect their privacy)
     
    digitalhaven, Aug 13, 2006 IP
  8. ip076

    ip076 Peon

    Messages:
    79
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well...here's what I've came up with. I would strongly suggest reading a tutorial or a book about PHP & MySQL Integration.

    
     
    //Build the connection and select the database
    $link = mysql_connect(HOST, USER, PASS) or die('Could not connect: ' . mysql_error());   //build MySQL Link    
       mysql_select_db(DB) or die('Could not select database');        //select database
     
    //Create the query string
    $Query = "SELECT COUNT(UserID) AS UserCount FROM UsersTable";
     
    //execute the query
    $Result = mysql_query($Query) or die("ERROR:" . mysql_error());
     
    //put the data from the one returned row into an array
    $Row = mysql_fetch_assoc($Result);
     
    //Take data from the UserCount field in that array and assign it to the UserTotal variable
    $UserTotal = $Row['UserCount'];
     
    //Use the variable $UserTotal to display the number of users, maybe something like:
     
    echo "$UserTotal users and growing every day!";
     
    
    PHP:
     
    ip076, Aug 15, 2006 IP