php - 并非所有数据都在显示

标签 php mysql sql database

我正在尝试回显下表中标题为 sectionamain 的数据,但我只从第一行 (TitleID = 1) 获取数据

|TitleID | MainTitle            | 
|1       |This is a title       | 
|2       |This is another title |

下面是我使用的 PHP 代码:

function get_practices_titles() {
    global $connection;
    $query = "SELECT * ";
    $query .= "FROM sectionamain ";
    $query .= "ORDER BY TitleID ASC";
    $A_list = mysqli_query($connection, $query);
    confirm_query($A_list);
    return $A_list;    
}

function practices_titles() {
   $output = "<div class=\"container inner\">\n";
   $output .= "<div class=\"wrap\">\n";
   $A_set = get_practices_titles();
   while ($list_A = mysqli_fetch_assoc($A_set)) {
       $output .= "<h1 class\=showcontent\" id=";
       $output .= htmlentities($list_A["TitleID"]);
       $output .= ">";
       $output .= htmlentities($list_A["MainTitle"]);
       $output .= "</h1>";
       mysqli_free_result($A_set);
       $output .="</div>\n</div>";
       return $output;
    };
}

在此先感谢大家的帮助。

最佳答案

我认为您需要将 mysqli_free_result($A_set); 移到 while 循环之外。

在完成循环之前,您正在摆脱结果。在 while 循环完成后将其移动到。

来自文档:http://php.net/manual/en/mysqli-result.free.php

You should always free your result with mysqli_free_result(), when your result object is not needed anymore.

但您仍然需要它 - 您在仅遍历一个结果后释放内存。

关于php - 并非所有数据都在显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50765126/

相关文章:

PHP Mod_rewrite

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

javascript - Ajax 发送并保存 Base64 编码图像到服务器

php - 一位数字验证码匹配,PHP

php - 使用 PHP 在 WAMP 服务器上进行 MySQL 转储

php - 找到出现次数最多的值并按其排序

php - 如何检查另一个表的最后 N 行中是否存在值?

sql - 查询中的多个连接 - 可以替换以获得性能吗?

php - 如果没有唯一列不存在,MySQL插入多条记录

mysql - 无法将数据保存到 mysql 数据库,在 gradle 项目中,BindingResult 和 bean 名称 'goal' 的普通目标对象都不能作为请求属性