SQL Add total amount of entries in a table

Discussion in 'Databases' started by bigpapa, Nov 13, 2008.

  1. #1
    In my database, I have a table "clients"

    In the table, it stores their name, email, etc, etc.

    I am trying to write something simple to display the number of clients that are in my database so that on my php page I can have something like:


    Total number of clients: $totalclients

    Ive been messing around and searching and cant find the solution to this simple problem. :confused:
     
    bigpapa, Nov 13, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    SELECT COUNT(*) AS client_count FROM clients_table;
     
    jestep, Nov 13, 2008 IP
  3. bigpapa

    bigpapa Banned

    Messages:
    273
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Im getting a Parse error: syntax error, unexpected T_STRING
     
    bigpapa, Nov 13, 2008 IP
  4. penalty

    penalty Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    you need to make a query with that string.

    
    $sql = "SELECT COUNT(*) AS client_count FROM clients_table";
    
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    
    echo "Total clients: ".$row['client_count'];
    
    Code (markup):
     
    penalty, Nov 14, 2008 IP
    Halobitt likes this.