我有一个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