Thread: count & max

  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Melbourne, Australia
    Rep Power
    I need to count the rows in a mysql table and to find the max value of a column. I
    am selecting count and max with mysql queries, but fail getting the results from my php code. For counting the rows I also tried mysql_fetch_array and then counting the rows in the array, but it didn't work either. Does someone know how to retreive the results of count() and max() ?

    Have fun (What else can you do until you die?)
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Rep Power
    you can find out both the things very easily..

    if you can issue a select statement like following can get you both count & max

    "SELECT count(*) as cnt,max(coulmn) as max_val from tblname";

    then you can get the vallues printed very easily..

    //database connectivity

    //select your databasse..

    $query="SELECT count(*) as cnt,max(coulmn) as max_val from tblname";

    //issue query..

    //total records to array..

    echo "Total number of record".$rows["cnt"];
    echo "Max value of column is ".$rows["max_val"];

    //echo "total number of records using mysql number of rows funtion is".mysql_num_rows($result);


    you can get the total record using mysql_num_rows() as well..

    SR - Career Portal

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. How to count max appearances?
    By Stew_McGruff in forum MySQL Help
    Replies: 8
    Last Post: December 13th, 2003, 05:27 PM
  2. Explaining Arrays?
    By Obscurity in forum C Programming
    Replies: 2
    Last Post: December 6th, 2003, 02:46 AM
  3. words count in a sentence
    By alebaba in forum C Programming
    Replies: 5
    Last Post: November 22nd, 2003, 08:54 AM
  4. Need to count clicks.. with a twist.
    By Jadey in forum PHP Development
    Replies: 0
    Last Post: November 19th, 2003, 01:07 PM
  5. Selecting MAX values
    By bajanagent in forum PHP Development
    Replies: 14
    Last Post: May 4th, 2003, 10:55 PM

IMN logo majestic logo threadwatch logo seochat tools logo