2
Hello, I have a huge doubt.
I need to show in my table, in the home page of my site, which field of 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.
Explaining better: this field of higher value is the number of times a student has picked up books in the library. the code must show on the home page which field has the highest loan value and show the name of the student.
in my code, I was able to show only the highest value field the student name could not make appear.
Look at my code. this is only from 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.
I’ll try here
– Guilherme Henrique
@Guilhermehenrique I edited the code.
– user28595
I did as you described, but something is still wrong. after declaring the name in the query, until entering the student’s series, in the code shows name and series, next to the value, but is not showing the highest value, but rather a random value, the highest value in my table is 9 with the name of John Peter, on the page is showing Ana Luiza with the value of 3. I wonder what can be?
– Guilherme Henrique
@Guilhermehenrique edited the question, with another solution approach
– user28595
Now I finally got it, I didn’t use max(), but I changed the structure of the query, in the same way I use the other pages I use select. was thus '$sql_visualize = mysql_query ("SELECT serie, name, times FROM enroll_students order by times desc limit 1"); while ($line = mysql_fetch_array ($sql_view)){ $serie = $line ['serie']; $name = $line ['name']; $max = $line ['times'];'. ai gave right now. vlw Diego
– Guilherme Henrique