此查詢輸出每個結果6次:因此,對於一列以「亞青」的主體,它會被輸出爲:亞青
亞青
亞青
亞青
阿約
亞青
SELECT查詢輸出每個單個結果六次
function get_comments($page_type, $spot) {
$query = mysql_query("
SELECT
comments.user_id AS user_id,
comments.page_type AS page_type,
comments.spot AS spot,
comments.comment AS comment,
comments.timestamp AS timestamp,
users.first_name AS first_name,
users.last_name AS last_name
FROM comments, users
WHERE page_type = '$page_type' AND spot = '$spot' AND (comments.user_id = users.user_id OR comments.user_id = '0')
ORDER BY timestamp DESC
");
while($fetch = mysql_fetch_assoc($query)) {
$comment = $fetch['comment'];
$timestamp = $fetch['timestamp'];
$timestamp_date = date('M d y\'', $timestamp);
$timestamp_time = date('g:m', $timestamp);
$comments_user_id = $fetch['user_id'];
if(date('H', $timestamp) > 12) {
$am_pm = 'pm';
} else {
$am_pm = 'am';
}
$first_name = $fetch['first_name'];
$last_name = $fetch['last_name'];
?>
<div id="replies">
<?php if($comments_user_id == '0') {echo 'Guest';} else { echo $first_name.' '.$last_name; } ?><br />
<?php echo $timestamp_date; ?><br />
<?php echo $comment; ?>
</div>
<?php
}
}
在這裏$ PAGE_TYPE和$發現是指:http://localhost/ $ PAGE_TYPE/$現貨
u能在你輸出的地方發佈代碼?問題可能在那裏,如果不是在數據本身 – xbonez
有多少'註釋'有'user_id = 0'? –
你是對的!如果user_id = 0,它會相乘。我將如何解決這個問題? – Graham