php - Why won't this exit out the while loop? -


i'm trying exit outside while look, script can post wordpress.com blogs. however, when try use break; inside if statement, loop continues.

this function starts script , handles 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 article database every time doesarticleexist() returns 1:

function getnewarticle() { $start = gettime();  global $db; $count = $db->query("select * flog_articles"); $count = $count->num_rows; $offset = mt_rand(0, $count - 1); $stmt = "select * 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 script checks see if article exists in database. if doesn't, returns 0. if does, returns 1.

function doesarticleexist($url, $id) { $start = gettime();  global $db;  $count = $db->query("select * flog_posted http = $url , 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, script gets article database. after gets article, checks see if article/url combination exists in table of same database. if not exist, want post wordpress blog, , break out of loop, won't post again.

the problem not exit loop. because exist values not being passed?

don't use break. use this

$willstop=false; while (($id != 0)&&(!$willstop)) {     $start = gettime();      doesarticleexist($url, $id);     if ($exist == 0)         {             wordpress($title, $content, $mail, $tags, $url, $id);             $willstop=true;               $end = gettime();              echo  '<strong>exist while</strong>: '.round($end - $start,4).' seconds<br />';          }     list($id, $title, $content, $tags) = getnewarticle();        echo 'i cant stop';  } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -