×

Please Login or Register to continue.

3
(7.5K Views)

I wish to write a code in PHP to retrieve the highest value from an array of numeric values stored in a table in mysql database. I addition, i also need to write a corresponding javascript code on the HTML FORM to do a similar thing as the PHP code.
(210 Points)
in PHP

Share

4 Answers
(7.3K Points)
3

Thanks for posting your question. If you want to retrieve the highest value of data from the MYSQL database using PHP programming then you should use the maximum (max)  function and then you can use that value where you want to use it. Retrieving the largest value from the MYSQL database using PHP. 

First of all, create a query and select the maximum value of the table. 

Use mysqli_fetch_array to fetch that value and use max with the array. You will get the highest value from the MYSQL database using PHP. 

$sql= mysqli_query( "SELECT MAX( id ) AS max FROM `db_table`;" );
$res = mysqli_fetch_array( $sql);
$highestValue = $res['max'];

 


Comment

(9.4K Points)
2

You can use the query below to retrieve the highest numeric value from the MYSQL database in PHP. 

"SELECT MAX(student_no) AS Higheststudent_no
 FROM records";

 


Comment

(9.4K Points)
2

I have written another answer. If you want to fetch the largest number from the MYSQL database with another column then you can use the query like below 

Fetch the largest numeric value from the MYSQL database in  PHP -

SELECT std_d, std_name, MAX(std_marks)

 


Comment

(4.3K Points)
(edited)
2

Maybe I am late in answering and the answer will be used for future reference. I read your description and I can understand your concern. You want to fetch the maximum  (Highest number ) value from the MYSQL database table in PHP. I'm right? 

Let's discuss the max() function. The max() function is an in-built function in PHP. You can use the max() function to retrieve the maximum value and display that value on-page. 

If you want to fetch the minimum number from the MySQL database table, then use the min() function of PHP. The min() function is also a in-built function in PHP. 

<?php 

$result =mysqli_query($mysqli, "SELECT  MAX( column_name) as max , MIN(column_name) as min FROM mytable_name");

      while($res = mysqli_fetch_array($result)) { 



           $max = $res['max']; 

           echo 'Highest Number :'.$max.'<br>'; 



 $min=$res['min'].'<br>'; 

         echo 'Lowest Number :'.$max.'<br>'; 

 }

?> 

This will produce the highest and lowest number from the database table. 

 


Comment

Related Questions :-

Featured Items:-


Certificate system in PHP website | PHP scripts

$22



Home Credito loan finance management multipurpose system in PHP

$65



Result management system with Marksheet in PHP website | PHP Scripts

$39




Your Answer

You can post your answer after login..