Select the maximum value of a colum in MySQL

Total Post:13


 1301  View(s)
Rate this:
 All I want to do is select the maximum value of a column in MySQL. Like this:
$max = "SELECT MAX(Id) FROM trialtabel2"; 
$max1 =  mysqli_query($dblink, $max); 
echo= $max1;
My debugger is just saying that it is a query returning a 0 boolean value (false)
  1. Re: Select the maximum value of a colum in MySQL

    We need to fetch the data from the mysqli_result object that was returned to you when you executed your query using mysqli_query.
        $max = "SELECT MAX(Id) as id FROM trialtabel2"; 
        $max1 =  mysqli_query($dblink, $max); 
        $row = mysqli_fetch_assoc($max1);    // this was missing
        echo $id;
    Note: I removed the loop because with MAX query without any grouping you will get only 1 row returned. If you had multiple rows in result set you would need to loop through all of them


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.