I have a table JT with the following columns:
Id | Name | Date
1 | John | 2015-01-01
2 | Alex | 2016-01-01
3 | Pete | 2016-01-01
4 | Alex | 2016-08-08
5 | John | 2016-08-08
I want to count the number of rows with the same date. I have done this by:
$query_21="SELECT Date, COUNT(*) AS total FROM JT GROUP BY Date";
$result_21=mysql_query($query_21);
while($row = mysql_fetch_array($result_21)) {
echo $row['Date'] . ":";
echo $row['total'] . "<br>";
}
That works fine returning:
2015-01-01: 1
2016-01-01: 2
2016-08-08: 2
However, I have a variable $Name, and I want to make the call so a row is only inserted in the resulting array if $Name is included in one of the rows during the count. So if $Name = "John" it should return:
2015-01-01: 1
2016-08-08: 2