gpt4 book ai didi

php - mysqli_fetch_array while 循环列

转载 作者:行者123 更新时间:2023-11-29 15:45:05 24 4
gpt4 key购买 nike

应该是非常基本的,但我无法让它工作。我有这个代码来迭代 mysqli 查询:

while($row = mysqli_fetch_array($result)) {
$posts[] = $row['post_id'].$row['post_title'].$row['content'];
}

它可以工作并返回:

Variable #1: (Array, 3 elements) ↵ 0 (String): "4testtest" (9 characters) 1 (String): "1Hello world!Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!" (99 characters) 2 (String): "2Sample PageThis is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes)." (161 characters)

问题是它将所有三列放入一列中,因此我无法单独访问它们。

例如:

0 (String): "4testtest" (9 characters)

应该分为4,测试,测试

当我这样做时:

while($row = mysqli_fetch_array($result)) {             
$posts['post_id'] = $row['post_id'];
$posts['post_title'] = $row['post_title'];
$posts['type'] = $row['type'];
$posts['author'] = $row['author'];
}

它只输出 1 行,而不是全部三行……

非常感谢任何帮助!

最佳答案

从 MySQL 获取所有值:

    $post = array();
while($row = mysqli_fetch_array($result))
{
$posts[] = $row;
}

然后,获取每个值:

<?php 
foreach ($posts as $row)
{
foreach ($row as $element)
{
echo $element."<br>";
}
}
?>

回显值。或者从 $post 变量中获取每个元素

关于php - mysqli_fetch_array while 循环列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57149328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com