Thread: count & max

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

    Join Date
    Aug 2000
    Location
    Melbourne, Australia
    Posts
    4
    Rep Power
    0
    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
    Location
    London
    Posts
    987
    Rep Power
    15
    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..

    <?
    $con=mysql_connect('localhost','username','password');
    //database connectivity

    mysql_select_db('databasename',$con);
    //select your databasse..

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


    $result=mysql_query($query,$con);
    //issue query..

    $rows=mysql_fetch_array($result);
    //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 -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "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, 06:27 PM
  2. Explaining Arrays?
    By Obscurity in forum C Programming
    Replies: 2
    Last Post: December 6th, 2003, 03:46 AM
  3. words count in a sentence
    By alebaba in forum C Programming
    Replies: 5
    Last Post: November 22nd, 2003, 09:54 AM
  4. Need to count clicks.. with a twist.
    By Jadey in forum PHP Development
    Replies: 0
    Last Post: November 19th, 2003, 02:07 PM
  5. Selecting MAX values
    By bajanagent in forum PHP Development
    Replies: 14
    Last Post: May 4th, 2003, 11:55 PM

IMN logo majestic logo threadwatch logo seochat tools logo