You are here:  » Send row["id"] to the function


Send row["id"] to the function

Submitted by russellharrower on Tue, 2010-09-28 08:06 in

Hi I need away to add row["id"] to the function so I can insert it into the DB when it is adding stories to the db

<?php
  
include_once("config/db.php");
  require(
"MagicParser.php");
 
$sql "SELECT * FROM rssfeeds";
 
$result mysql_query($sql) or die(mysql_error());
    
// Print out result
    
while($row mysql_fetch_array($result))
    {
     function 
myRecordHandler($record)
      {
        
// This is where you write your code to process each record, such as loading a database
        // The following code will print out each field in your sample data:  
       
$sqla "SELECT * FROM aflstories WHERE url = '".$record["LINK"]."'";
        if (
mysql_num_rows(mysql_query($sqla)))
        {
         }
        else
        {
        
$url $record["LINK"];
        
$raw file_get_contents($url);
        
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
        
$content str_replace($newlines""html_entity_decode($raw));
        
$start strpos($content,'</script></div><br />');
        
$end strpos($content,'<div class="articleDetails">',$start) + 8;
        
$table substr($content,$start,$end-$start);
        
$table str_replace("</script></div><br />"""$table);
        
$table str_replace("<div cla","",$table);
        
mysql_query("INSERT INTO aflstories (teamid, title, url, content, image)
        VALUES ('"
.$teamid."', '".$record["TITLE"]."', '".$record["LINK"]."', '".$table."', '".$record["ENCLOSURE-URL"]."')");
        print 
"Success.<br/>";
        }
      }
      
MagicParser_parse($row["url"],"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
      }
?>

Submitted by support on Tue, 2010-09-28 08:41

Hi Russell,

Very straight forward; first thing I would do is move your myRecordHandler function outside of the while() loop, and then simply declare $row as global - that should be all you need to do! Try something like this;

<?php
  
include_once("config/db.php");
  require(
"MagicParser.php");
  
$sql "SELECT * FROM rssfeeds";
  
$result mysql_query($sql) or die(mysql_error());
  function 
myRecordHandler($record)
    {
      global 
$row;
      
$sqla "SELECT * FROM aflstories WHERE url = '".$record["LINK"]."'";
      if (
mysql_num_rows(mysql_query($sqla)))
      {
      }
      else
      {
      
$url $record["LINK"];
      
$raw file_get_contents($url);
      
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
      
$content str_replace($newlines""html_entity_decode($raw));
      
$start strpos($content,'</script></div><br />');
      
$end strpos($content,'<div class="articleDetails">',$start) + 8;
      
$table substr($content,$start,$end-$start);
      
$table str_replace("</script></div><br />"""$table);
      
$table str_replace("<div cla","",$table);
      
mysql_query("INSERT INTO aflstories (teamid, title, url, content, image) VALUES ('".$teamid."', '".$record["TITLE"]."', '".$record["LINK"]."', '".$table."', '".$record["ENCLOSURE-URL"]."')");
      print 
"Success.<br/>";
    }
  }
  while(
$row mysql_fetch_array($result))
  {
    
MagicParser_parse($row["url"],"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  }
?>

Hope this helps!
Cheers,
David.