MYSQL NUM ROWS To Count Rows

MYSQL NUM ROWS

Counting Rows with mysqli_num_rows function can provide useful pieces of data. The following example demonstrates how to gather gather distinct first names in a table sorted by date.

$names = "select distinct firstname from table_sort WHERE date<='2012-01-27' ";
$result= mysqli_query($db, $names);
$name_count = mysqli_num_rows($result);
echo "There are ".$name_count." rows.<br/><br/>";

$names2 = "select DISTINCT firstname from table_sort WHERE date>='2012-01-01' ";
$result= mysqli_query($db, $names2);
$name_count2 = mysqli_num_rows($result);
echo "There are ".$name_count2." rows.<br/><br/>";

$myvalues=array("After_2011" => $name_count, "Before_2011" => $name_count2);

echo "There are ".count($myvalues)." values in the array.<br/><br/>
There are ".($name_count+$name_count2)." rows in total.";