나는 외모를 털어 놓고 나가기 위해이 스크립트를 Wordpress.com 블로그에 올릴 수 있습니다. 그러나, 심지어 내가 휴식을 사용하려고 할 때; if 문 내부에서 루프가 계속됩니다.왜 while 루프가 종료되지 않습니까?
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';
}
}
이 기능은 데이터베이스에서 모든 시간 doesARticleExist를 (문서를 잡고) 반환 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 />';
}
그리고이 스크립트를 확인
이 기능은 기본적으로 스크립트를 시작하고 게시를 처리 해당 기사가 데이터베이스에 있는지 확인하십시오. 그렇지 않으면 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 />';
}
기본적으로 스크립트는 데이터베이스에서 아티클을 가져옵니다. 기사를 가져온 후 해당 기사/URL 조합이 동일한 데이터베이스의 다른 테이블에 있는지 확인합니다. 그것이 존재하지 않으면, 나는 그것을 WordPress의 블로그에 게시하고, 다시 루프에서 빠져 나와서 다시 게시하지 않기를 바란다.
유일한 문제는 루프를 종료하지 않는다는 것입니다. 존재 가치가 전달되지 않기 때문입니까?