Jump to content

[SOLVED] How to get rid of this warning when my code is working fine.


divadiva

Recommended Posts

Experts

 

I ran my system in localhost it works absolutely fine.But now I have shifted it to production server.I get these warning which I am unable to figure out:

 

Notice: Trying to get property of non-object in /var/www/html/site.php on line 80.This is driving me insane.

 

Here is my code of this site:

 

<?php
include("mainpage.php");
include_once("database.php");
set_time_limit(0); 
parseData();

function parseData()	
{
	handlOldData('BB');

$content = geCurlContent("http://");

if (preg_match_all("/auctionList.taf\?sid=133&m=(.*?)&sort=manufacturer&_UserReference=/si", $content, $array))		
{		
	$i=0;

	$eachLink = "http://auctionList.taf?sid=133&m=VALUE&sort=manufacturer";

	while($i<count($array[1]))	//iterate over all match of the links which contains our desired data
	{
		$actualLink = str_replace('VALUE', $array[1][$i], $eachLink);
		callEachPage($actualLink);	//call function for each of these pages 
		//			echo '<br/>'.$actualLink;
		$i++;													
	}
}
}		

function geCurlContent($link)		
{
// initialize curl
$ch = curl_init(); 
// set the url to fetch
curl_setopt($ch, CURLOPT_URL, $link); 
// don't give me the headers just the content
curl_setopt($ch, CURLOPT_HEADER, 0); 
// return the value instead of printing the response to browser
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
// write data to variable
$content = curl_exec($ch); 
// close curl
curl_close($ch); 	

return $content;
}

function callEachPage($link)
{			

//echo $link;
$content = geCurlContent($link);	//we get the expected page. now need parse to save actual data in db
/*
* matching a specific patter so that we get a 2D array $array. Here we will only find out our expected table portion. 
*/
if(preg_match_all("/<TABLE WIDTH=\"100%\" CELLPADDING=2 CELLSPACING=1 BORDER=0 CLASS=color>(.*?)<\/table>/si", $content, $array))
{		
	$content = '<table>'.str_replace("&", "&", $array[1][0]).'</table>';
}

//now the table portion will be passed to domdocument to parse each column
$dom = new DOMDocument();	//dom document object
$dom->loadHTML($content);	//load the tbody part

    // find all tables
    $tables = $dom->getElementsByTagName('table');

    // get all rows from the first table
    $rows = $tables->item(0)->getElementsByTagName('tr');

    foreach ($rows as $row) //for each tr
{
        $cols = $row->getElementsByTagName('td');	//get columns for the current row

	if(strlen($cols->item(2)->nodeValue))	//if has at least manufacturer
	{
		if(checkExists('BB', $cols->item(0)->nodeValue) == 0)
		{
			//build insert query
			$query =  "insert into data(WebsiteId, Process, Manufacturer, Model, Wafersize, Serial, ProductionYear, Site, onmarket) values";
			$query .=  "('".trim($cols->item(0)->nodeValue)."', '".$cols->item(1)->nodeValue."', '".$cols->item(2)->nodeValue."', '".$cols->item(4)->nodeValue."', '".$cols->item(5)->nodeValue."', '', '".$cols->item(6)->nodeValue."', 'BBEM', 1)";
			//print '<br/>'.$query;
			executeNonQuery($query);	//execute the insert query
		}	
	}


   }	
}
echo 'Data parsed and saved successfully.';
include("footer.php");
?>

 

Thanks in advance.

try printing out, see if has a node, if not wrap it like you have the next line...


	print_r($cols->item(2)->nodeValue);
	if(strlen($cols->item(2)->nodeValue))	//if has at least manufacturer
	{
		if(checkExists('BB', $cols->item(0)->nodeValue) == 0)
		{

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.