我有一個while循環從查詢調用$ result。Mysql查詢While while循環內的錯誤
這裏面while循環我有其他兩個查詢$ anchors1和$ anchors2
第一個檢索前兩排;
第二個應該檢索後面的使用偏移量。
由於某些原因,查詢似乎互相影響,不顯示3行並拉出不應該在那裏的重複行。
有什麼辦法可以解決這個問題嗎? 如果我刪除第一個,則第二個查詢將起作用。反之亦然。
該平臺是Wordpress。
while($slice = mysql_fetch_assoc($result)){
$i++;
if($enable_position1 == 'y' && $i == $position[0]):
$anchors1 = mysql_query("SELECT * FROM anchors WHERE site_url = '$site_current' LIMIT 3");
while($anc = mysql_fetch_assoc($anchors)){
$site_anchor = $anc['site_anchor'];
$site_current = $anc['site_current'];
echo '<li><a href="'.$site_current.'" title="'.$site_anchor.'" target="_self">'.$site_anchor.'</a></li>';
}
elseif($enable_position2 == 'y' && $i == $position[1]):
$anchors2 = mysql_query("SELECT * FROM anchors WHERE site_url = '$site_current' LIMIT 999 OFFSET 3");
while($anc2 = mysql_fetch_assoc($anchors2)){
$site_anchor2 = $anc2['site_anchor'];
$site_current2 = $anc2['site_current'];
echo '<li><a href="'.$site_current2.'" title="'.$site_anchor2.'" target="_self">'.$site_anchor2.'</a></li>';
}
else:
the_post();
endif;
}
非常感謝!
在您的第二個查詢中,當然'OFFSET 3'會導致無限結果集中的第三行作爲有限結果集的第一行返回。你不需要把它改成'OFFSET 4'嗎? – Atonewell 2012-01-06 22:17:27