我正在为我的大学作业做一个项目。除了我的活动列表,其他所有内容都可以正常使用。问题是,每当我尝试查看活动列表时,它仅返回1个活动,而不是所有仍在进行的活动,当我从phpMyAdmin
手动运行查询时,它将返回所有查询,但PHP却没有似乎做对了,我也不知道为什么。
我已经尝试过从phpMyAdmin
运行查询并简化查询,还添加了一堆调试代码来查看我要去哪里,但所有值均正确,查询正确且{{1 }}运行查询就很好了。
phpMyAdmin
答案 0 :(得分:0)
<?php
$query = "SELECT * FROM activities";
$result = mysqli_query($link, $query);
if(!$result) {
echo "<p class='text-danger'>There are no activities to display.</p>";
} else {
while($row = mysqli_fetch_assoc($result)) {
$activity_id = $row['id'];
$activity_name = $row['name'];
$activity_description = $row['description'];
$activity_end_date = $row['endDate'];
$activity_start_date = $row['startDate'];
$activity_type = $row['type'];
$activityAuthor = $row['author'];
$activityPublished = $row['publishedAt'];
$activityLikes = $row['likes'];
$activityDislikes = $row['dislikes'];
$activityComments = $row['comments'];
$activityViews = $row['views'];
$query = "SELECT * FROM users WHERE Username = '$activityAuthor'";
$result = mysqli_query($link, $query);
if(!$result) {
die("MySQL Query Failed: " . mysqli_error($link));
}
$row = mysqli_fetch_assoc($result);
$authorID = $row['id'];
}
$output.="<div class='row'>
<div class='col-md-6'>
<a href='#'>
<img class='img-fluid rounded mb-3 mb-md-0' src='img/<?php echo '$activity_type';?>.jpeg' alt=''>
</a>
</div>
<div class='col-md-6'>
<h3><?php echo $activity_name;?></h3>
<p class='lead text-secondary'>Proposed by <a class='text-secondary lead' href='profile.php?id=<?php echo $authorID;?>'><?php echo $activityAuthor;?></a> at <?php echo $activityPublished;?></p>
<p><?php echo $activity_description;?></p>
<p><strong>Starts at:</strong> <?php echo $activity_start_date;?></p>
<p><strong>Ends at:</strong> <?php echo $activity_end_date;?></p>
<a class='btn btn-outline-success' href='config/like.php?page=<?php echo $page;?>&post=<?php echo $activity_id;?>'><i class='far fa-thumbs-up'></i> <?php echo $activityLikes;?></a>
<a class='btn btn-outline-danger' href='config/dislike.php?page=<?php echo $page;?>&post=<?php echo $activity_id;?>'><i class='far fa-thumbs-down'></i> <?php echo $activityDislikes;?></a>
<button class='btn btn-outline-secondary'><i class='far fa-comment-dots'></i> <?php echo $activityComments;?></button>
<button class='btn btn-outline-secondary'><i class='far fa-eye'></i> <?php echo $activityViews;?></button>
<div class='mt-3'><a class='btn btn-primary' href='activity.php?post=<?php echo $activity_id;?>&page=<?php echo $page;?>&commentpage=1'>View Activity</a></div>
</div>
</div>";
}
?>
<?php echo $output; ?>