【问题标题】:how to get result number in fetch [duplicate]如何在获取中获取结果编号[重复]
【发布时间】:2018-12-22 03:01:10
【问题描述】:

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

<?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 中写帖子的数量

*如果翻译不清楚,我很抱歉

【问题讨论】:

  • 你试过 $result2->num_rows; ?

标签: php


【解决方案1】:

我想你正在寻找

$result2->num_rows

查看文档: http://php.net/manual/en/mysqli-result.num-rows.php

【讨论】:

    【解决方案2】:

    检查以下网址,您的疑问可能会澄清

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 2020-03-31
      • 2017-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      相关资源
      最近更新 更多