0

Thanks in advance for any help and understanding with the fact that I'm still very inexperienced...

Despite a long search through questions and examples, I still can't properly query/echo MAX.

If you could show me an exact example of the proper code I'd be very grateful.

Since I think I understand (?) you cannot mix mysql with mysqli, I'm going to provide here a sample of my code that actually works for purpose other than getting the max value:

$query = "SELECT iltr FROM massimo_demo_copy WHERE UPDT=3";
$result = $conn->query($query);
$row = mysqli_fetch_assoc($result);
$LTR = $row['iltr'];

echo "$LTR;

again, this code example works but it's not what I'm trying to do. What I am trying to do is get the maximum value from another column (points). I've tried too many syntax versions to list them...

I just wanna echo the max value from the points column with a mysqli syntax that is compatible with the example of the type of code above.

this is the first version I tried and it fails:

$query = "SELECT MAX(points) FROM massimo_demo_copy";
$result = $conn->query($query);
$row = mysqli_fetch_assoc($result);
$maxpts = $row['points'];

echo $maxpts;

I tried many others but lers start with that one

Thanks

Took Zoxor
  • 23
  • 8

2 Answers2

0

Your $query should look something like this SELECT MAX(points) as points FROM massimo_demo_copy

  • $query = "SELECT MAX(points) FROM massimo_demo_copy"; $result = $conn->query($query); $row = mysqli_fetch_assoc($result); $maxpts = $row['points']; echo $maxpts; – Took Zoxor Jul 07 '16 at 12:39
  • sorry i didnt know how to format in the comment section and accidentally posted. i put the same in the question. – Took Zoxor Jul 07 '16 at 12:43
-1

If I understand your question, I resolved like this:

$example_max_value = "SELECT max(value) as max_value FROM table WHERE tableid={$var_ID}";
$get_result = mysqli_query($conectionDB,$example_max_value);
$get_result = mysqli_fetch_assoc($get_result);
$max_value = $get_result["max_value"];

Output:
max_value in the DB from table where table has the especifically range

David Buck
  • 3,752
  • 35
  • 31
  • 35