为什么这不会退出while循环?

Tif*_*ney -2 php while-loop

我试图在外面退出,所以我的脚本可以发布到Wordpress.com博客.但是,即使我尝试使用休息; 在if语句中,循环继续.

此函数启动脚本并基本上处理发布:

function getFlogArticle($url, $mail) {  
list($id, $title, $content, $tags) = getNewArticle();
while ($id != 0)
{
    $start = getTime(); 
    doesArticleExist($url, $id);
        if ($exist = 0)
            {
                wordpress($title, $content, $mail, $tags, $url, $id);
                break;  
                $end = getTime(); 
                echo  '<strong>Exist While</strong>: '.round($end - $start,4).' seconds<br />'; 
            }
    list($id, $title, $content, $tags) = getNewArticle();   
    echo 'I cant stop'; 
}
}
Run Code Online (Sandbox Code Playgroud)

每次doARticleExist()返回1时,此函数都会从数据库中获取文章:

function getNewArticle() {
$start = getTime(); 
global $db;
$count = $db->query("SELECT * FROM flog_articles");
$count = $count->num_rows;
$offset = mt_rand(0, $count - 1);
$stmt = "SELECT * FROM flog_articles LIMIT 1 OFFSET $offset";
$result = $db->query($stmt);
$post = $result->fetch_array(MYSQLI_ASSOC);
return array($post['article_id'], $post['article_title'], $post['article_content'], $post['article_keyword']);
$end = getTime(); 
echo  '<strong>getNewArticle()</strong>: '.round($end - $start,4).' seconds<br />';
}
Run Code Online (Sandbox Code Playgroud)

此脚本检查文章是否存在于数据库中.如果没有,则返回0.如果是,则返回1.

function doesArticleExist($url, $id) {
$start = getTime(); 
global $db; 
$count = $db->query("SELECT * FROM flog_posted WHERE http = $url AND article_id = $id");
$count = $count->num_rows;

if ($count > 0) {
    $exist = 1;
    return $exist;
} else{
    $exist = 0;
    return $exist;
}
$end = getTime();
echo  '<strong>doesArticleExist()</strong>: '.round($end - $start,4).' seconds<br />';
}
Run Code Online (Sandbox Code Playgroud)

基本上,脚本从数据库中获取文章.获得文章后,它会检查该文章/ url组合是否存在于同一数据库的另一个表中.如果它不存在,我希望它发布到wordpress博客,然后突破循环,所以它不会再发布.

唯一的问题是它甚至没有退出循环.是因为存在的价值没有被传递吗?

Nie*_*sol 6

使用==了比较.你在做什么是分配0$exist,它总是会失败的if声明.