javascript - Display Output During Each Iteration of for Loop -


i want show message displaying result of each iteration of loop in php.

i have tried several methods using jquery, ajax etc doesn't seem fit needs or either not getting work around them.

what script does?

it scans website, grab links, visits each link 1 one , grab image each page , send wordpress including title , image.

what's problem?

the problem there can several links (more 200), though scripts displays message regarding success shows messages after whole loop finished executing.

what want do?

now, want during each iteration message should shown on browser rather waiting loop complete i.e. during 1st iteration (posted successfully) during 2nd (not posted) , on...

here code:

<?php  $category = array();  ($i = 0; $i < count($result); $i++) {   set_time_limit(30);    // check if post exists   global $wpdb;   $query = $wpdb->prepare('select id ' . $wpdb->posts .      ' post_name = %s',sanitize_title_with_dashes($result[$i]->title));   $cid = $wpdb->get_var($query);    if (!empty($cid))   {      echo $result[$i]->title .          " <font style='color:#ff0000; font-weight:bold;'>already exists.</font><br />";   } else   {      $inner_html = file_get_html($result[$i]->href);       $inner_result_image = $inner_html->find('meta[property=og:image]',1);      $inner_result_cats = $inner_html->find('a[rel=category tag]');       $title = $result[$i]->title;      $body = "<a href='$inner_result_image->content'><img src='$inner_result_image->content' /></a>";       // automatically create new category if doesn't exist.       foreach ($inner_result_cats $cats)      {          if (!($cats->innertext == "jobs"))          {               array_push($category,$cats->innertext);               $count = 0;               // cities              if (search_city($cats->innertext))              {                  wp_insert_term($cats->innertext,'category',array(                      'description' => '',                      'slug' => '',                      'parent' => '14')); // jobs city              } else              {                  $count += 1;              }                // qualification              if (search_qualification($cats->innertext))              {                  wp_insert_term($cats->innertext,'category',array(                      'description' => '',                      'slug' => '',                      'parent' => '51')); // jobs qualification              } else              {                  $count += 1;              }                // international jobs              if (check_international(parse_url($cats->href,php_url_path)))              {                  wp_insert_term($cats->innertext,'category',array(                      'description' => '',                      'slug' => '',                      'parent' => '52')); // international jobs              } else              {                  $count += 1;              }               if ($count == 3)              {                  wp_insert_term($cats->innertext,'category',array('description' => '','slug' =>                          ''));               }            } // end if newspaper check        } // end if auto category       echo "<br />";        $postdate = new ixr_date(strtotime($date));        $title = htmlentities($title,ent_noquotes,"utf-8");       $content = array(          'title' => $title,          'description' => $body,          'mt_allow_comments' => 1, // 1 allow comments          'mt_allow_pings' => 1, // 1 allow trackbacks          'post_type' => 'post',          'date_created_gmt' => $postdate,          'categories' => $category,          );       // create client object      $client = new ixr_client('http://localhost/fdj/xmlrpc.php');       $username = "admin";      $password = "password";      $params = array(0,          $username,          $password,          $content,          true); // last parameter 'true' means post immediately, save draft set 'false'       // run query php      if (!$client->query('metaweblog.newpost',$params))      {          die('something went wrong - ' . $client->geterrorcode() . ' : ' . $client->              geterrormessage());          echo $title . " <font style='color:#ff0000; font-weight:bold;'>not posted.</font><br />";      } else          echo $title . " <font style='color:#00ff00; font-weight:bold;'>posted successfully.</font><br />";   }  } // end if main   ?> 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -