php - Get two types of number of rows with minimum lines -
i have following query.
$sql = "select customer furniture id = :id , category = :cat"; $stmt = $connectdb->prepare($sql); $stmt->execute(array(':id'=>$id, ':cat'=>"1")); $resulta = $stmt->fetchall(pdo::fetch_assoc); $rowcount = count($result);
this works perfectly. have requirement number of rows where id = :id , category = :cat
number of rows where category = :cat
. possible both of them without having write select query lines twice?
you can use conditional sum 2 different counts as
select sum(id = :id , category = :cat) count1, sum(category = :cat) count2 furniture;
later fetch records , values of count1
, count2
note : if row count return 1 since using aggregate function
Comments
Post a Comment