i want to get the order id maximum by the relative user id
$order_id = "select * from products_orders where order_user_id = $user_id AND MAX(order_id) ";
$ord_del = mysqli_query($con,$order_id) ;
$ord_row = mysqli_fetch_assoc($ord_del);
i try this method but this wont work
2
Answers
The
MAX
SQL command is a group function which needs to indicate with the common columns. So just adding theGROUP BY
should work as you want.You may amend the select statement so that it is
order by order_id desc
and then just retrieve the 1st record (limit 0,1
)In that case only the record with the max order_id will be retrieved.
So based on your original code, you may use