foreach if-else 中断帮助

发布于 2024-11-05 23:39:05 字数 2163 浏览 4 评论 0原文

foreach($sites as $url)
{
    print_r($url);  
    $db = mysql_connect("localhost","root","11") or die("\nerror connecting".  mysql_error());  
    mysql_select_db("website_categorization") or die("\n error selecting database" );  
    mysql_real_escape_string($url);  
    mysql_query("INSERT INTO url_main(Url) VALUES('$url')") or trigger_error(mysql_error());   
    $result = mysql_query("SELECT ID from url_main where url='$url'");  
    list($url_id) = mysql_fetch_row($result);  
    $keyword = get_meta_tags("http://".$url);                                   
    if(array_key_exists('keywords', $keyword))                                    
            $tag = $keyword['keywords'];  
    elseif(array_key_exists('Keywords', $keyword))  
            $tag = $keyword['Keywords'];  
    else  
         {  mysql_query("INSERT INTO uncategorized(Url) VALUES('$url')") or trigger_error(mysql_error());  
            break;  
         }  
}

即使程序的控制达到 else 语句,我也想继续运行我的程序。你能帮我做什么,让我的程序运行其他 $url 值,即使遇到 else 结构......

这是代码的其余部分。

$keyword_array = preg_split('/[\s,]+/ ', $tag);  
foreach( $keyword_array as $url_keyword )        
{  
        mysql_real_escape_string($url_keyword);  
        $query = "SELECT ID from category_keyword where Keyword='$url_keyword'";  
        $result = mysql_query($query);  
        while($row=mysql_fetch_array($result))  
        {
             $out = mysql_query("INSERT INTO url_keyword(Url_ID,Keyword,Keyword_ID) values ($url_id, '$url_keyword','$row[ID]')");  
        }  
        $query2 = "SELECT ID_Category, sum(Score) as score from `category_keyword` as ck ,`url_keyword` as uk where  ck.ID = uk.Keyword_ID and Url_ID=$url_id group by ID_Category";  
        $result2 = mysql_query($query2);  
    }

    while($row2 = mysql_fetch_array($result2))
    {
             print_r($row2);
            if( $row2['score'] > $THRES )
            {
                $query3="INSERT INTO url_category_map(Url_ID, Category_ID) values( $url_id, $row2[ID_Category])";
                $out3 = mysql_query($query3);
                $FLAG=true;
            }
     }
}
foreach($sites as $url)
{
    print_r($url);  
    $db = mysql_connect("localhost","root","11") or die("\nerror connecting".  mysql_error());  
    mysql_select_db("website_categorization") or die("\n error selecting database" );  
    mysql_real_escape_string($url);  
    mysql_query("INSERT INTO url_main(Url) VALUES('$url')") or trigger_error(mysql_error());   
    $result = mysql_query("SELECT ID from url_main where url='$url'");  
    list($url_id) = mysql_fetch_row($result);  
    $keyword = get_meta_tags("http://".$url);                                   
    if(array_key_exists('keywords', $keyword))                                    
            $tag = $keyword['keywords'];  
    elseif(array_key_exists('Keywords', $keyword))  
            $tag = $keyword['Keywords'];  
    else  
         {  mysql_query("INSERT INTO uncategorized(Url) VALUES('$url')") or trigger_error(mysql_error());  
            break;  
         }  
}

I want to continue my program to run even if control of program reaches else statement. Can u help me what i have to do to let my program running for other $url values even if else structure is encountered....

This is the rest of the code.

$keyword_array = preg_split('/[\s,]+/ ', $tag);  
foreach( $keyword_array as $url_keyword )        
{  
        mysql_real_escape_string($url_keyword);  
        $query = "SELECT ID from category_keyword where Keyword='$url_keyword'";  
        $result = mysql_query($query);  
        while($row=mysql_fetch_array($result))  
        {
             $out = mysql_query("INSERT INTO url_keyword(Url_ID,Keyword,Keyword_ID) values ($url_id, '$url_keyword','$row[ID]')");  
        }  
        $query2 = "SELECT ID_Category, sum(Score) as score from `category_keyword` as ck ,`url_keyword` as uk where  ck.ID = uk.Keyword_ID and Url_ID=$url_id group by ID_Category";  
        $result2 = mysql_query($query2);  
    }

    while($row2 = mysql_fetch_array($result2))
    {
             print_r($row2);
            if( $row2['score'] > $THRES )
            {
                $query3="INSERT INTO url_category_map(Url_ID, Category_ID) values( $url_id, $row2[ID_Category])";
                $out3 = mysql_query($query3);
                $FLAG=true;
            }
     }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杯敬自由 2024-11-12 23:39:05

只需完全删除 break 即可。

Just remove the break entirely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文