如何在mysqli_fetch_object中计算帮助我

时间:2016-10-03 06:11:17

标签: php mysql

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); 
查询后通过

获取

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
 }

我找到了出版商,但不是伯爵。我该如何计算?

3 个答案:

答案 0 :(得分:1)

根据您的查询,您可以像这样

$runrows->COUNT(publisher);  

或将查询更改为。像这样设置别名如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";

并得到这样的

 $runrows->count; 

答案 1 :(得分:1)

试试这个:

echo $getq2 = "SELECT publisher,COUNT(publisher) as pub_count 
// provide a proper column aliasing so that you can refer it

并使用它:

echo $count = $runrows->pub_count;

答案 2 :(得分:0)

使用像COUNT(publisher) As count这样的查询,您可以

echo $count=$runrows->count;