Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Posts
    13

    Unanswered: Showing Data From Database

    Hello,
    I'm not much of a databse person but I really want to be able to show a total amount of members onto a homepage.

    In my database, one of my tables is "users" and it shows a total # of users.
    Click image for larger version. 

Name:	capture1.jpg 
Views:	50 
Size:	114.2 KB 
ID:	6211

    I want to get that total amount of users and show it on a homepage of a website.

    Can someone please give me an example of the coding I need to add to a index.php page in order to show this?
    Thats my 2 cents,
    Amanda
    BizBla

  2. #2
    Join Date
    Jan 2006
    Posts
    26
    PHP Code:
      $query="SELECT COUNT(somefield) AS thefield FROM tablename";
      
    $result=mysql_query($query,$db);
      
    $array=mysql_fetch_array($result);
      
    $totalcount=$array[thefield]; 

  3. #3
    Join Date
    Aug 2006
    Posts
    13
    Quote Originally Posted by Eiolon
    PHP Code:
      $query="SELECT COUNT(somefield) AS thefield FROM tablename";
      
    $result=mysql_query($query,$db);
      
    $array=mysql_fetch_array($result);
      
    $totalcount=$array[thefield]; 
    Hi Eiolon,
    I really appericiate your help above, however, is there any way you can please show me with the field filled in? I've tried many different times but cant get it to show. I dont know the fields. The table is "users" and its under "Results" as the picture shows.
    Thats my 2 cents,
    Amanda
    BizBla

  4. #4
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    To get just a count of the number of rows in the "users" table, try this -
    PHP Code:
    // connect to the database server and select your database here...

    $query "SELECT count(*) FROM users";
    $result mysql_query($query) or die('Query failed: ' mysql_error());
    $row mysql_fetch_row($result); // if the query did not fail, there will be a count of the number of rows
    echo $row[0]; // output the results wherever you want... 

  5. #5
    Join Date
    Aug 2006
    Posts
    13
    Quote Originally Posted by dbmab
    To get just a count of the number of rows in the "users" table, try this -
    PHP Code:
    // connect to the database server and select your database here...

    $query "SELECT count(*) FROM users";
    $result mysql_query($query) or die('Query failed: ' mysql_error());
    $row mysql_fetch_row($result); // if the query did not fail, there will be a count of the number of rows
    echo $row[0]; // output the results wherever you want... 
    Hi dbmab,
    That is exactally what I needed Thank you!
    Everythings working properly now.
    Thats my 2 cents,
    Amanda
    BizBla

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •