有人能告訴我下面的代碼有什麼問題嗎?出於某種原因,它只返回一個結果。我檢查了使用mysql_num_rows()從查詢返回了多少行,它說了兩個,那麼爲什麼我只看到一個結果呢?while循環只顯示一個結果
function get_events($amount) {
global $wpdb;
$today = date('Y-m-d');
$result = mysql_query(
"SELECT
wp_eventscalendar_main.eventTitle, wp_eventscalendar_main.eventDescription, wp_eventscalendar_main.eventStartDate, wp_eventscalendar_main.postID, wp_postmeta.post_id, wp_postmeta.meta_key, wp_postmeta.meta_value
FROM
wp_eventscalendar_main, wp_postmeta
WHERE
STR_TO_DATE('$today', '%Y-%m-%d') < wp_eventscalendar_main.eventStartDate AND
wp_postmeta.post_id = wp_eventscalendar_main.postID AND
wp_postmeta.meta_key = '_thumbnail_id'
ORDER BY wp_eventscalendar_main.eventStartDate ASC
LIMIT 10") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$thumbpostid = $row['meta_value'];
$result2 = mysql_query("
SELECT
post_id, meta_key, meta_value
FROM
wp_postmeta
WHERE
post_id = $thumbpostid AND
meta_key = '_wp_attached_file'") or die(mysql_error());
while($row2 = mysql_fetch_array($result2)) {
$thumburl = explode(".",$row2['meta_value']);
}
$shortdesc = limitWrds($row['eventDescription'], 10);
$rawdate = date('d M', strtotime($row['eventStartDate']));
$date = explode(' ', $rawdate);
$postlink = strtolower(str_replace(' ', '-', preg_replace("/[^a-zA-Z0-9\s]/", "", $row['eventTitle'])));
echo "<div class=\"event\">
<div class=\"txt\">
<h5><a href='/" . $postlink ."'>" . $row['eventTitle'] . "‚ " . $date[1] ." " . $date[0] . "</h5></a>
<p>" . $shortdesc ."…
<a href=\"" . $postlink . "\">find out more »</a></p>
</div><img src='/wp-content/uploads/". $thumburl[0] ."-42x42.jpg' alt='". $row['eventTitle'] ."' />
</div>";
echo _clear('15');
}
}
感謝,
查看日誌如果在運行代碼時出現錯誤,可能在第二行中有些字段爲空,如$ row ['eventDescription']並且出現錯誤 –