I'm trying to exit outside this while look, so my script can post to Wordpress.com blogs. However, even when I try to use break; inside the if statement, the loop continues.
This function starts up the script and basically handles the posting:
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';
}
}
This function grabs the article from the database every time doesARticleExist() returns 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 />';
}
And this script checks to see if the article exists in the database. If it doesn't, it returns a 0. If it does, it returns a 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 />';
}
Basically, the script gets an article from the database. After it gets the article, it checks to see if that article/url combination exists in another table of the same database. If it does not exist, i want it to post to the wordpress blog, and then break out of the loop, so it won't post again.
The only problem is that it does not even exit the loop. Is it because the exist values are not being passed?