更新查询语句多次循环结果

时间:2014-06-23 13:18:43

标签: php mysql sql while-loop sql-update

我使用了以下循环条件来更新数据库。我从select语句中获取多行。现在我想使用update语句将这些行存储在数据库中。在这种情况下,多个更新语句将被循环,因此我的数据库没有得到更新。我只想循环更新查询一次,select语句中的多行存储在数据库中。它只是一个小错误,我无法识别错误的循环,我想。

这是我的代码:

if($param['aktion'] == 'save-widget-news')
{

        if(($param['news'])==4){

        $sql=" SELECT DISTINCT ad_news_texte.headline, ad_news.datum_archiv,ad_news_texte.id
            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( )";    
        }
            elseif(($param['news'])==6){

        $sql=" SELECT DISTINCT ad_news_texte.headline, ad_news.datum_archiv,ad_news_texte.id
            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( ) ) +42
            DAY AND curdate( )";

            }
            elseif(($param['news'])==10){

        $sql=" SELECT DISTINCT ad_news_texte.headline, ad_news.datum_archiv,ad_news_texte.id
            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( ) ) +70
            DAY AND curdate( )";

            }

            $sql_select=mysql_query($sql);  
            while ($row = mysql_fetch_assoc($sql_select)) {
            echo $update="UPDATE dashboard_widget_users w SET w.configuration='".mysql_real_escape_string(serialize($row['headline']))."' WHERE w.dsnr_yw_user =12 AND w.dsnr_dashboard_widget=2 ";
            $update_news=mysql_query($update, $myConnection);
            }

在firebug中,我在这里检查了它是如何循环并多次执行更新条件,这是我不想要的:

UPDATE dashboard_widget_users w 
SET w.configuration='s:65:\"AutoDo! News: Neue Pflichtfelder für Neuwagen bei AutoScout24.de!\";' 
WHERE w.dsnr_yw_user =12 AND w.dsnr_dashboard_widget=2;

UPDATE dashboard_widget_users w 
SET w.configuration='s:65:\"New intercompany prices for delivery to Schmitz Cargobull Russia.\";' 
WHERE w.dsnr_yw_user =12 AND w.dsnr_dashboard_widget=2;

UPDATE dashboard_widget_users w 
SET w.configuration='s:22:\"AutoDo! startet durch.\";' 
WHERE w.dsnr_yw_user =12 AND w.dsnr_dashboard_widget=2;

0 个答案:

没有答案