Show the highest value of a field, together with the field name

2

Hello, I have a huge question.

I need to show in my table, on the home page of my site, which field in my table has the highest value and next to this field, show not only the highest value but also the name of the person who has this value. >

Better explaining: this field of higher value is the number of times a student has taken books in the library. the code should show on the home page which field is the highest value of loans and show the name of the student.

In my code, I was able to show only the most valuable field the name of the student could not make appear.

See my code. this is just the table in question.

<table width="757" border="3" align="center" cellpadding="1" cellspacing="1" bgcolor="#006699">
  <tr>
    <td width="572" align="center">
      <p>Selecione <span class="destaques">EMPRESTIMOS</span> para emprestar o livro pego paraseu aluno.</p>
      <p>Selecione <span class="destaques">RELATORIO DE EMPRESTIMOS</span> para remover o livro do nome dos alunos.</p>
      <p>Selecione <span class="destaques">CADASTRO</span> para cadastrar <span class="destaques">LIVROS</span> - <span class="destaques">ALUNOS</span>.</p>
      <p>Selecione <span class="destaques">RELATORIOS</span> para ver a relacao de <span class="destaques">LIVROS</span> - <span class="destaques">ALUNOS</span> - <span class="destaques">AUTORES</span> - <span class="destaques">EDITORAS</span> - <span class="destaques">EMPRESTIMOS</span>.</p>
    </td>
    <? $consulta=m ysql_fetch_assoc(mysql_query( 'SELECT MAX(vezes) FROM cadastro_alunos')); $nome=$ consulta [ 'nome']; $max=i ntval($consulta[ 'MAX(vezes)']); ?>
    <td width="168" align="center" bgcolor="#FFCC00">Aluno (a) que mais se destacou em Leitura é:
      <? echo $nome ?> <font class="bem_vindo"></font> - com
      <? echo $max ?>Livros</td>
  </tr>
</table>

Does anyone have any idea how to show the student's name along with the highest value ???

grateful.

    
asked by anonymous 01.12.2015 / 01:17

1 answer

2

Reviewing your code, I think you do not even need to use max() , just use the query:

SELECT nome,vezes FROM cadastro_aluno order by vezes desc limit 1

See it working: link

References:

link

    
01.12.2015 / 01:27