title: How can I use this code to add data from multiple feeds in my Database?
body: <p>So, currently, the code I'm using, only enters the data from last feed in the array namely <code>feed4</code> in the databse and doesn't add the data from the other 3 feeds, how can I fix this, here is the code: </p>
  
  <pre><code>&lt;?php
  
  $db_hostname="";
  $db_username="";
  $db_password="";
  
  $all_urls = array('feed1', 'feed2', 'feed3', 'feed4');
  
  try
  {
  
  
  $db = mysql_connect($db_hostname,$db_username,$db_password);
  if (!$db)
  {
      die("Could not connect: " . mysql_error());
  }
  mysql_select_db("dbname", $db);
  
  foreach ($all_urls as $url) {
  
  libxml_use_internal_errors(true);
  $RSS_DOC = simpleXML_load_file($url);
  }
  if (!$RSS_DOC) {
      echo "Failed loading XML\n";
      foreach(libxml_get_errors() as $error) {
          echo "\t", $error-&gt;message;
      }
  }
  
  
  $rss_title = $RSS_DOC-&gt;channel-&gt;title;
  $rss_link = $RSS_DOC-&gt;channel-&gt;link;
  $rss_editor = $RSS_DOC-&gt;channel-&gt;managingEditor;
  $rss_copyright = $RSS_DOC-&gt;channel-&gt;copyright;
  $rss_date = $RSS_DOC-&gt;channel-&gt;pubDate;
  $rss_author = $RSS_DOC-&gt;channel-&gt;author;
  
  
  foreach($RSS_DOC-&gt;channel-&gt;item as $RSSitem)
  {
  
      $item_id    = md5($RSSitem-&gt;title);
      $fetch_date = date("Y-m-j G:i:s"); 
      $item_title = $RSSitem-&gt;title;
      $item_date  = date("Y-m-j G:i:s", strtotime($RSSitem-&gt;pubDate));
      $item_time  = date("H:i:s", strtotime($RSSitem-&gt;pubDate));
      $item_url   = $RSSitem-&gt;link;
      $item_author = $RSSitem-&gt;author;
  
  
      $item_exists_sql = "SELECT item_id FROM tablename where item_id = '" . $item_id . "'";
      $item_exists = mysql_query($item_exists_sql, $db);
      if(mysql_num_rows($item_exists)&lt;1)
      {
          $item_insert_sql = "INSERT INTO tablename(item_id, feed_url, item_title, item_date, item_time, item_url, item_author, fetch_date) VALUES ('" . $item_id . "', '" . $url . "', '" . $item_title . "', '" . $item_date . "', '" . $item_time . "', '" . $item_url . "', '" . $item_author . "', '" . $fetch_date . "')";
          $insert_item = mysql_query($item_insert_sql, $db);
          echo "Inserted into Databse Successfully";
      }
      else
      {
  
      }
  }
  
  
  } catch (Exception $e)
  {
  echo 'Caught exception: ',  $e-&gt;getMessage(), "\n";
  }
  ?&gt;
  </code></pre>
  
  <p>PS: I know mysql_* is deprecated, my production code will use mysqli.</p>