I am trying to get the number of rows meeting certain criteria from a database.
I have a MySQL phpMyAdmin database called ovs and in it there's a table called results with 10 columns and a sample of 5 rows so far. The column I am interested in is named chairperson. I want to get the number of rows that have Tony Montana as the chairperson. How do I accomplish this?
This code of mine does not seem to work. It doesn't even output anything.
<?php
$con=mysqli_connect("localhost","root","","ovs");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT COUNT(*) FROM results WHERE chairperson=Tony Montana";
if ($result=mysqli_query($con,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
printf("%d",$rowcount);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
This code does not seem to work. It doesn't even output anything. What is going on?