Gaurav Gaurav - 2 months ago 7
MySQL Question

how to get count in mysqli_fetch_object help me out

echo $getq2 = "SELECT publisher,COUNT(publisher) from (select publisher from wiley where $getq2_ UNION ALL SELECT publisher FROM elsevier WHERE $getq2_ UNION ALL SELECT publisher FROM sage WHERE $getq2_ UNION ALL SELECT publisher FROM indianjournal WHERE $getq2_) as publisher Group by publisher order by publisher";

$getquery1 = $conn->query($getq2);


after the query fetching through

while($runrows =mysqli_fetch_object($getquery1))
{
print_r($getquery1);

echo $pub=$runrows->publisher;
//getting the publisher list
echo $count=$runrows->count['publisher'];
//not grtting the publisher count
}


I'm getting the publisher, but not the count. How can I get the count?

Answer

As per your query you can get by like this

$runrows->COUNT(publisher);  

or change the query into . like this set the alias name like this COUNT(publisher) as count

echo $getq2 = "SELECT publisher,COUNT(publisher) as count from (select publisher from wiley where $getq2_ UNION ALL SELECT publisher FROM elsevier WHERE $getq2_ UNION ALL SELECT publisher FROM sage WHERE $getq2_  UNION ALL SELECT publisher FROM indianjournal WHERE $getq2_) as publisher Group by publisher order by publisher";

and get like this

 $runrows->count; 
Comments