我正在php中制作一个类似的系统,我有一个代码来获取所有喜欢使用帖子ID的人的用户名,如果他们不喜欢这篇文章,它会显示一个按钮,说像是帖子,如果他们没有,它会显示一个按钮,说不像帖子,如果没有像它会说“没有人喜欢这个帖子是第一个”。但是,当我将其添加在,它只能获得1用户名,即使多个人都喜欢的岗位,我怎么解决了这个问题,这里是我的代码:SQL只能得到1行
$fancy = $db->fetch("SELECT * FROM " . $prefix . "_fancy WHERE post_id = '" . $post_row['id'] . "' ORDER BY id");
if ($fancy) {
$name = $user->name($fancy['account_id']);
if ($account['id'] !== $fancy['account_id']) {
$fancytext = '<div>'.$name.' Like this post.<!-- BEGIN logged_in --> <a href="./?area=forum&s=topic&t='.$topic_id.'&f='.$pid.'"><img src="./template/default/images/like.png" alt="" border="0"/></a><!-- END logged_in -->
</div>';
} else {
$fancytext = '<div>'.$name.' Like this post.<!-- BEGIN logged_in --> <a href="./?area=forum&s=topic&t='.$topic_id.'&unf='.$pid.'"><img src="./template/default/images/unlike.png" alt="" border="0"/></a><!-- END logged_in -->
</div>';
}
} else {
$fancytext = '<div><i>No one has liked this post, be the first!</i> <!-- BEGIN logged_in --><a href="./?area=forum&s=topic&t='.$topic_id.'&f='.$pid.'"><img src="./template/default/images/like.png" alt="" border="0"/></a><!-- END logged_in -->
</div>';
}
请至少描述一下表格吗?谢谢 –
摆脱所有的造型;它不相关,使你的代码变得庞大。 – imulsion
你在查询中有一个WHERE。这可能是你的问题。数组中是否有多个'$ post_row ['id']'?你有没有回应该数组? – ntgCleaner