Reputation: 492
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
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