Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    Using min() to count an array size from a mySQL select -- how to do it?

    How do you tak the minimum value of an array from a mySQL select using min() in PHP?

    Code:
    $sql = "SELECT id, number FROM table";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
          $minNumber = $row[number];
    }
    
    $minArrayNumber = min($minNumber);  // this gives an error: Warning: Wrong parameter count for min()

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    In the code you posted, $minNumber is a variable, not an array -
    PHP Code:
    $minNumber $row[number]; 
    Try this -
    PHP Code:
    $minNumber[] = $row[number]; 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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