Kelson Batista
Kelson Batista

Reputation: 492

Select and print max value in mysql

I am trying to select max value and print but is not working

Does anybody can help me ?

$query = "SELECT MAX(price) FROM products WHERE user='".$user."'";
$result = $conn->query($query);
$price = $result["price"];
echo $price;

Upvotes: 0

Views: 286

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270513

You are using the alias price, so you need to assign it:

SELECT MAX(price) as price FROM products WHERE user='".$user."'

Or, you could use the query:

select price
from products
where user='".$user."'
order by price desc
limit 1;

Upvotes: 2

Related Questions