0

I used the following codes to find the maximum value of marks

 <?php
  $sql = mysql_query("SELECT MAX(marks) FROM participant ");
  $fetch = mysql_fetch_row($sql);
  $max_m = $data[0];


  $sql = mysql_query("SELECT st_name FROM participant WHERE marks='$max_m'");
  $fetch = mysql_fetch_row($sql);
  $st = $data[0];
  echo $st;
  ?>

but when I insert a mark that is 2-9 to test, the output become the student with that marks.

How to solve the problem? It works when i use 1 and the number between 10 and 20.(the full mark is 20)

gary luk
  • 23
  • 4
  • [First, read this.](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). No, really read it. Then erase your code and start over. Then, I'll ask why you aren't just using `SELECT st_name, MAX(marks) FROM participant;`? – miken32 Oct 19 '14 at 07:46
  • @miken32: 1. because it might be legacy code 2. Your query makes no sense. – zerkms Oct 19 '14 at 09:12
  • $sql = mysql_query("SELECT st_name FROM participant WHERE marks=max(marks)"); you can try this . – sharif2008 Oct 19 '14 at 10:59
  • May be it's because `MAX(marks)` is a number, while `'$max_m'` is not? – mustaccio Oct 20 '14 at 01:41

0 Answers0