0
Good,
I have a question about showing the number of records in a given table.
SELECT COUNT Nome FROM `tb_utilizador`
I want to show the number of records in a php table.
<?php
include("Config.php");
$sql = mysql_query("Select * From tb_utilizador");
mysql_query($sql) or die(mysql_error());
if($linhas == 0){
echo "Nada encontrado";
exit();
}
else{
while($row = mysql_fetch_array($sql)){
$ID = $row["id"];
if($linhas %2 == 0){
$cor = "#F0F0F0";
}
else{
$cor = "#E2EFFE";
}
echo "
<tr bgcolor=\"$cor\">
<td> $id</td>
</tr>";
}
}
?>
What’s going on? Something’s wrong?
– Miguel
In SQL gives this message Mysql messages : Documentation #1054 - Unknown column 'COUNT' in 'field list'
– ChrisAdler
I edited the question because "phpmyadmin" is not a "database", read this to understand the differences: What is the difference between mysql and phpmyadmin?
– Guilherme Nascimento
I agree with the answers you have. If you want to count the records and still use them is not worth making two querys for it. Just use
mysql_num_rows
. For information, the error you reported is caused by the wrong query syntax that uses COUNT. The correct one would be:SELECT COUNT(Nome) FROM tb_utilizador
.– Emerson JS