使用php和mysqli包含特定值的行数


How many rows contain a specific value using php and mysqli

我有一个类似的表"bookings"

bookings
    id      id_class    date                    day         name    
    1       2           2016-03-10 16:00:00     monday      Fredrik
    2       5           2016-03-11 16:00:00     tuesday     Richard
    3       7           2016-03-11 18:00:00     tuesday     Sara
    4       4           2016-03-11 15:00:00     tuesday     Fredrik

然后我使用php提取该表

<?php
    $result = $con->query("select * from bookings");
<?

我现在想要的是一个php函数,它告诉有多少行包含特定条目,如"id_class=2",或者有多少行(name=Fredrik)包含答案应该在0和正数之间。有办法吗?

使用何处获取特定条件

SELECT COUNT(*) FROM bookings WHERE id_class=2
SELECT COUNT(*) FROM bookings WHERE name='Fredrik'