Php Mysql查询While循环中的错误

Php Mysql查询While循环中的错误,php,mysql,wordpress,Php,Mysql,Wordpress,我有一个名为$result的查询中的while循环 在这个while循环中,我还有另外两个查询$anchors1和$anchors2 第一个检索前两行 第二个应使用偏移量检索后面的值 由于某些原因,这些查询似乎彼此交互,不显示3行,并拉取不应该存在的重复行。 此查询是否会产生干扰? 如果删除第一个查询,则第二个查询有效。反之亦然 平台是Wordpress while($slice = mysql_fetch_assoc($result)){ $i++; if($

我有一个名为$result的查询中的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; 

}
while($slice=mysql\u fetch\u assoc($result)){
$i++;
如果($enable_position1=='y'&&$i==$position[0]):
$anchors1=mysql\U查询(“从站点url='$site\U current'限制3的锚中选择*);
而($anc=mysql\u fetch\u assoc($anchors)){
$site_anchor=$anc['site_anchor'];
$site_current=$anc['site_current'];
回音“
  • ”; } elseif($enable_position2=='y'&&$i==$position[1]): $anchors2=mysql\U查询(“从站点url='$site\U current'限制999偏移量3的锚中选择*); 而($anc2=mysql\u fetch\u assoc($anchors2)){ $site_anchor2=$anc2['site_anchor']; $site_current2=$anc2['site_current2']; 回音“
  • ”; } 其他: _post(); endif; }

    非常感谢你

    在第二个查询中,使用变量
    $site\u current
    ,该变量在第一个查询的块中设置。这可能会导致干扰,具体取决于应用程序的设计方式。我想你是想把
    $site\u current2
    放在那里。

    在你的第二个查询中,
    OFFSET 3
    肯定会导致无限结果集中的第三行作为有限结果集的第一行返回。您不需要将其更改为偏移量4吗?这很有效,ty:)这很奇怪,但$site\u current具有相同的值(它是一个多平台应用程序)。我所做的是$site\u current2=$site\u current;并且应用了您建议的更改。为什么会产生干扰?可能是因为在第一个循环的每次迭代中都要重写变量。
    $site\u当前是否来自应用程序的其他部分?您应该避免重写变量,它们往往会导致像这样的错误。