我正在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