这只返回我的最后一行:
<?php
function all_infos_query() {
global $connection;
$query = "SELECT * ";
$query .= "FROM pages ";
$query .= "JOIN subjects ";
$query .= "ON pages.subject_id=subjects.id";
$infos_set = mysqli_query($connection, $query);
confirm_query($infos_set);
return $infos_set;
}
function infos_content() {
$infos_set = all_infos_query();
while($info = mysqli_fetch_assoc($infos_set)) {
$output = htmlentities($info["content"]);
$output .= " <br><br>";
}
mysqli_free_result($infos_set);
return $output;
}
?>
<?php echo infos_content() ?>
如果我像这样回应它可以工作(返回所有行):
<?php
$result = all_infos_query();
if($result === FALSE) {
echo "query failed: " . mysqli_error($connection);
}
else {
while($row = mysqli_fetch_array($result)) {
echo htmlentities($row['content']);
echo "<br><br>";
}
}
?>
我还需要在函数infos_content()中更改以获取所有行? 非常感谢!
答案 0 :(得分:2)
这是因为您为每个结果重新定义$ ouput
$output ='';
while($info = mysqli_fetch_assoc($infos_set)) {
$output .= htmlentities($info["content"]);
$output .= " <br><br>";
相反,在循环外创建$ ouput并附加到它...
{{1}}