PHP MySQL结果进入无限循环

用户名

嗨,我将sql查询结果存储在数据库中。我必须检查是否有任何行包含字符串'N;'。然后下一个sql语句应该执行。我有很多这样的字符串,这就是为什么要执行我的下一个sql语句。我已经尝试了以下代码,但是当我尝试运行该代码时,它会进入无限循环。谢谢。这是我的PHP代码:

while ($row = mysql_fetch_assoc($result)) {
        $config= $row['configuration'];     
        if($config=='N;')
        {
            $sql="SELECT DISTINCT ad_news_texte.id, ad_news_texte.headline, ad_news.datum_archiv FROM autodo.ad_news_texte INNER JOIN autodo.ad_news_oe ON ad_news_texte.news_id = ad_news_oe.id_ad_news INNER JOIN autodo.ad_news ON ad_news_oe.id_ad_news = ad_news.id WHERE ad_news.datum_archiv BETWEEN curdate( ) - INTERVAL DAYOFWEEK( curdate( ) ) +28 DAY AND curdate( )";
            $result = mysql_query($query, $myConnection);
        }
        else{                               
            $html .= '<table id="news">                     
                <a href="news.php?id=">
                <p class="welcome-subheadline"> '. $config .'</p></a>                   
                </table>';
        }
    }
盖瑟夫特

好的,所以我想念一些信息,但是我将尝试通过以下两种方法来解决您的问题:

如果您的sql提取与循环中的sql语句相同,则代码应如下所示:(在这种情况下,我看不到if语句的原因)

$sql="SELECT DISTINCT ad_news_texte.id, ad_news_texte.headline, ad_news.datum_archiv FROM autodo.ad_news_texte INNER JOIN autodo.ad_news_oe ON ad_news_texte.news_id = ad_news_oe.id_ad_news INNER JOIN autodo.ad_news ON ad_news_oe.id_ad_news = ad_news.id WHERE ad_news.datum_archiv BETWEEN curdate( ) - INTERVAL DAYOFWEEK( curdate( ) ) +28 DAY AND curdate( )";
$result = mysql_query($sql, $myConnection);

while ($row = mysql_fetch_assoc($result)) {
        $config= $row['configuration'];     
        if($config=='N;')
        {
            // If the sql is the same no need for another fetch
        }
        else{                               
            $html .= '<table id="news">                     
                <a href="news.php?id=">
                <p class="welcome-subheadline"> '. $config .'</p></a>                   
                </table>';
        }
    }

在第二种情况下,当sql语句不同时,代码应如下所示:

$result = mysql_query($sql, $myConnection);
while ($row = mysql_fetch_assoc($result)) {
        $config= $row['configuration'];     
        if($config=='N;')
        {
           $sql2="SELECT DISTINCT ad_news_texte.id, ad_news_texte.headline, ad_news.datum_archiv FROM autodo.ad_news_texte INNER JOIN autodo.ad_news_oe ON ad_news_texte.news_id = ad_news_oe.id_ad_news INNER JOIN autodo.ad_news ON ad_news_oe.id_ad_news = ad_news.id WHERE ad_news.datum_archiv BETWEEN curdate( ) - INTERVAL DAYOFWEEK( curdate( ) ) +28 DAY AND curdate( )";
           $result2 = mysql_query($sql2, $myConnection);
           while ($row2 = mysql_fetch_assoc($result2)) {
               //The rest of the code
           }

         }
            else{                               
                $html .= '<table id="news">                     
                    <a href="news.php?id=">
                    <p class="welcome-subheadline"> '. $config .'</p></a>                   
                    </table>';
            }
        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章