开发者

foreach if-else break help

开发者 https://www.devze.com 2023-03-04 15:54 出处:网络
foreach($sites as $url) { print_r($url); $db = mysql_connect(\"localhost\",\"root\",\"11\") or die(\"\\nerror connecting\".mysql_error());
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='开发者_JAVA百科$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;
            }
     }
}


Just remove the break entirely.

0

精彩评论

暂无评论...
验证码 换一张
取 消