[英]Is it possible to avoid the “AS” parameter when counting total rows of a mysql table? (php)
[英]Not showing total rows from table PHP MySQL
我想顯示表中的所有行並獲取標題並在另一個表中搜索標題。 如果我回顯它正確顯示的總行數(816)。 但是如果添加下面的代碼它只顯示表中的(414)結果。
$viewss1=$con->query("SELECT COUNT(reference_id) FROM reference WHERE
reference LIKE '%$paper_title%'");
$cview1=$viewss1->fetch_row();
$countt1=$cview1[0];
如果我添加它顯示一半的結果。 那是為什么?。 我不知道為什么。 我的完整代碼附在下面。 謝謝你。
$sql="SELECT * FROM table";
$result=$con->query($sql);
$record=array();
if($result)
{
if($result->num_rows)
{
while($row=$result->fetch_object())
{
$record[]=$row;
}
}
}
foreach($record as $r)
{
$paper_title=$r->paper_title;
echo $paper_title;
// If i add the below code it shows half results.
$viewss1=$con->query("SELECT COUNT(reference_id) FROM reference WHERE
reference LIKE '%$paper_title%'");
$cview1=$viewss1->fetch_row();
$countt1=$cview1[0];
echo "<br>";
echo $r->upload_paper_id;
echo $countt1;
echo "<br>";
}
最后我得到了答案。如果任何行有空值,它將停止循環。所以最好檢查是否為空。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.