Click here to Skip to main content
15,037,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I want to count the number of same item in a column in my table in database.
For example I have my column "lecturer" and the different items are "Good","Bad"
I want to count the number of "Good"..

Can you give me the PHP code for this..

I have tried
PHP
<?php <br mode="hold" /?>$con =
mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_lec", $con);
$result = mysql_query("SELECT COUNT (lecturer)FROM tbl_lec WHERE lecturer="Good"");

echo "<h1><table class="TFtable">
<tr>
	<td>Lecturer</td>
	
	</tr>";

	while($row = mysql_fetch_array($result))
	   {
	  echo "<tr>";
	  echo "<td>" . $row['lecturer'] . "</td>";
	  echo "</tr>";
	  }
	echo "</table></h1>";

mysql_close($con) 
?> 

but it is not working

Help me please
Posted
Updated 6-Mar-14 20:29pm
v2
Comments
Peter Leow 7-Mar-14 2:46am
   
"it is not working" is not clear enough, what error?
I did see one mistake, try changing WHERE lecturer="Good"" to WHERE lecturer='Good'"
Member 10626057 7-Mar-14 3:45am
   
Its displaying
"; while($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; } echo "
" . $row['lecturer'] . "
"; mysql_close($con) ?>

1 solution

"it is not working" is not clear enough, what error? I did see one mistake, try changing
WHERE lecturer="Good"" 

to
WHERE lecturer='Good'"
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900