应该是非常基本的,但我不能让它工作。我有此代码来迭代一个mysqli的查询:mysqli_fetch_array虽然循环列
while($row = mysqli_fetch_array($result)) {
$posts[] = $row['post_id'].$row['post_title'].$row['content'];
}
它的工作原理和回报:
变量#1:(阵列,3片)↵ 0(字符串): “4testtest”( 9个字符) 1(String):“欢迎来到WordPress!欢迎使用WordPress。这是您的第一篇文章,编辑或删除它,然后开始写博客! (99个字符) 2(String):“2样本PageThis是一个示例页面,它不同于博客文章,因为它将保留在一个位置,并将显示在 您的网站导航(在大多数主题中)。 (161个字符)
问题是,它将所有三个colums放在一列中,所以我无法分开访问它们。
这例如:
0(字符串): “4testtest”(9个字符)
应当分开成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行而不是所有三个...
任何帮助,非常感谢!
你是如何“打印”的第二个选项哟试过? –
'<?php foreach($ posts as $ post):?> \t \t \t \t <?php echo $ post_id; ?> <?php echo $ post_title; ?> <?php echo $ type; ?> <?php echo $ author; ?> <?php endforeach; ?> – Sebastian
同时检查http://php.net/manual/en/mysqli-result.fetch-assoc.php和http://php.net/manual/en/mysqli-result.fetch中的程序while循环示例-array.php –