N3lson Posted July 21, 2012 at 10:35 AM Report Share #469482 Posted July 21, 2012 at 10:35 AM boas estou a ter o seguinte problema com este código $result = mysql_query("SELECT * FROM jog_futsal_seniores ORDER BY numero ASC"); echo "<table class='jogadores' cellspacing='1'> <tr> <th class='num'>Nº</th> <th class='tit'>Nome</th> <th class='tit'>Posição</th> <th class='tit'>Clube Anterior</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='num'>" . $row['numero'] . "</td>"; echo "<td><a href='./sql/detalhes_seniores_futsal.php?id=$row[id]' target='detalhes'>" . $row['nome'] . "</a></td>"; echo "<td>" . $row['posicao'] . "</td>"; echo "<td>" . $row['clube'] . "</td>"; echo "</tr>"; } echo "</table>"; $num_rows = mysql_num_rows($result); $sql = ("SELECT SUM(altura) AS Total FROM jog_futsal_seniores"); $soma_altura=mysql_query($sql); #$media_alt = $soma_altura / $num_rows; echo $soma_altura; echo'<br>'; echo $num_rows; Deveria fazer este output: 2256 14 Mas em vez disso faz isto Resource id #7 14 O que eu pretendia era obter a media de altura You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it. Link to comment Share on other sites More sharing options...
anolsi Posted July 21, 2012 at 10:39 AM Report Share #469483 Posted July 21, 2012 at 10:39 AM Se leres com atenção o que é que a função devolve percebes que te falta aí algo: http://php.net/manual/pt_BR/function.mysql-query.php O que tu querias era algo do género: $sql = ("SELECT SUM(altura) AS Total FROM jog_futsal_seniores"); $resultado=mysql_query($sql); $linha = mysql_fetch_assoc($resultado); $soma_altura = $linha['Total']; 1 Report "Nós somos o que fazemos repetidamente, a excelência não é um feito, e sim, um hábito."Não respondo a questões por PM que possam ser colocadas no fórum! Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 21, 2012 at 10:41 AM Report Share #469484 Posted July 21, 2012 at 10:41 AM o resultado de $soma_altura=mysql_query($sql); é um recordset, que internamente é um resource ... se pretendes "ler" o recordset, primeiro necessitas de pedir pelo registo(s) do recordset $recordset=mysql_query($sql); // fazer o query a base de dados $record=mysql_fetch_assoc($recordset); // ler o registo do recordset $soma_altura=$record['Total']; // guardar o campo "Total" do registo 1 Report IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
N3lson Posted July 21, 2012 at 10:43 AM Author Report Share #469485 Posted July 21, 2012 at 10:43 AM (edited) Muito Obrigado anolsi e HappyHippyHippo pela ajuda já funciona... Ainda tenho muito a aprender. Edited July 21, 2012 at 10:58 AM by N3lson You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now