foreach if-else 中断帮助
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需完全删除
break
即可。Just remove the
break
entirely.