【发布时间】:2021-11-30 20:33:18
【问题描述】:
/* To sort the id and limit the post by 40 */
$sql = "SELECT * FROM requests";
$result = $conn->query($sql);
$sqlall= "SELECT * FROM requests ";
$resultall = $conn->query($sqlall);
$i = 0;
if ($result->num_rows > 0) {
// Output data of each row
$idarray= array();
while($row = $result->fetch_assoc()) {
echo "<br>";
// Create an array to store the
// id of the blogs
array_push($idarray,$row['id']);
}
}
else {
echo "0 results";
}
?>
<?php
for($x = 1; $x < 40; $x++) {
// This is the loop to display all the stored blog posts
if(isset($x)) {
$query = mysqli_query(
$conn,"SELECT * FROM `requests`");
$res = mysqli_fetch_array($query);
$email1 = $res['email1'];
$msg1= $res['msg1'];
$subject1 = $res['subject1'];
$name1 = $res['name1'];
$id = $res['id'];
输出是从我的数据库的第一行读取数据的 40 张卡片。谁能帮忙? 我正在使用 xampp。 这段代码是为了显示循环,但如果有人想要完整的代码是here
【问题讨论】:
-
您将所有 ID 存储在数组
$idarray中,然后您只需再次运行 40 次相同的查询并始终提取相同的第一行。 -
@AllanSharad 下面的答案对您有帮助吗?如果是这样,请记住将其标记为已接受和/或投票。如果没有帮助,请解释原因。谢谢。