如何获取结果编号

时间:2018-12-22 03:01:10

标签: php

我有猫,也有帖子,这是我的代码:

<?php
        $sel_query = "SELECT * FROM cats ORDER BY cat_id ASC";
        $result = mysqli_query($con,$sel_query);
        while($data = mysqli_fetch_assoc($result)) 

        {  // start insert cats

        echo "<h1>Cat Name: ".$data["cat_id"]."</h1>";

            $sel_query2 = "SELECT * FROM selecom WHERE cel_cat='".$data['cat_id']."' ";
            $result2 = mysqli_query($con,$sel_query2);
            while ($data2 = mysqli_fetch_assoc($result2)) 

                {    // start insert posts
                    echo "<h2>Post: ".$data2['cel_golid']."</h2>";
                    echo "<h2>total Post Numbers in this cat: ?????????????????????????????????</h2>";
                }
        }
?>

我需要插入帖子总数(放置问号)

示例: 如果某只猫有2个帖子,我想在(问号位置)2中写帖子数。

*如果翻译不清楚,我表示歉意

2 个答案:

答案 0 :(得分:0)

我认为您正在寻找

$result2->num_rows

请参阅文档: http://php.net/manual/en/mysqli-result.num-rows.php

答案 1 :(得分:0)

检查下面的URL,您的疑问可能会澄清

https://www.w3schools.com/php/func_mysqli_num_rows.asp