我有一个从数据库中查找结果的函数。我正在使用while loopwithmysqli_fetch_assoc()从数据库中获取结果。但是页面一直在加载并且没有显示任何错误。环形 <?php while ($job = mysqli_fetch_assoc(find_all_jobs())) { ?> <tr class="custom-table-body-titles"> <td><?php echo $job['updated-at']; ?></td> <td> <a href="#" class="text-dark"><?php echo $job['title']; ?></a> </td> <td>0/<?php echo $job['required_freelancers']; ?></td> <td><?php echo $job['delivery_time']; ?> Days</td> <td>$<?php echo $job['budget']; ?></td> <td> <a href="job_details.html" class="btn btn-sm btn-primary">Apply</a> </td> </tr> <?php } ?>功能function find_all_jobs() { global $connection; $sql = "SELECT * FROM jobs ORDER BY job_id DESC LIMIT 10"; $stmt = mysqli_stmt_init($connection); mysqli_stmt_prepare($stmt, $sql); $result = mysqli_stmt_execute($stmt); if(!$result) { die("Database query failed." . mysqli_stmt_error($stmt)); } return mysqli_stmt_get_result($stmt); mysqli_stmt_close($stmt); }
1 回答
慕尼黑8549860
TA贡献1818条经验 获得超11个赞
将结果分配find_all_jobs()给变量并运行循环:
<?php
$jobs = find_all_jobs();
while ($job = mysqli_fetch_assoc($jobs)) { ?>
因为目前您find_all_jobs()在每次while迭代中执行。并因此导致无限循环。
- 1 回答
- 0 关注
- 57 浏览
添加回答
举报
0/150
提交
取消