...

View Full Version : code help please! data inserts into db but page displays nothing?



LJackson
03-26-2010, 01:58 AM
Hi All

i have a page which updates my db, now the db updates fine but nothing appears on the page but i dont know why.

here (http://www.kernow-connect.com/awtest2.php)is the page

and here is my code

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
//AMAZON KEYS
$public_key = "";
$private_key = "";

//Affiliate Window Config Files
define('API', 'PS');
require_once('shopwindow.client/constants.inc.php');
require_once('shopwindow.client/classes/class.ClientFactory.php');
require_once('dbinfo.php');
require('functions.php');


# Username and password constants are defined in constants.inc.php
$oClient = ClientFactory::getClient(API_USERNAME, API_PASSWORD, API_USER_TYPE);
?>
</head>

<body>
<?php
$categories = array("DVD","CD","Xbox 360","PS3","Wii","DS","PSP","Blu-Ray","Books");

foreach($categories as $category)
{
switch($category)
{
case "DVD";
$item_list = array
("48150464","72625332","100707130","97338263","50427160","80860160","100706404","51068575","96006630","50462126");
$catID_No1 = "235";
$catID_No2 = "240";
$SearchIndex = "DVD";
$extras = "dvd";
break;
case "CD";
$item_list = array
("99256871","56825535","99744386","102568733","100017746","103499339","96262871","96264441","96252533","96264569");
$catID_No1 = "241";
$catID_No2 = "245";
$SearchIndex = "Music";
$extras = "";
break;
case "Xbox 360";
$item_list = array
("99631466","104326073","38268847","96291423","102323997","104326075","100019542","101043360","80867348","102324014");
$catID_No1 = "579";
$catID_No2 = "521";
$SearchIndex = "VideoGames";
$extras = "xbox 360";
break;
case "PS3";
$item_list = array
("46626197","102486070","96288914","72193311","104068035","95766003","102324013","50959882","104951951","102318489");
$catID_No1 = "579";
$catID_No2 = "521";
$SearchIndex = "VideoGames";
$extras = "ps3";
break;
case "Wii";
$item_list = array
("101198423","99339086","80862281","102324015","102326251","99631113","104545623","104759522","102327751","99319635");
$catID_No1 = "579";
$catID_No2 = "521";
$SearchIndex = "VideoGames";
$extras = "wii";
break;
case "DS";
$item_list = array
("53747257","47865474","99176385","102311177","99176390","102299977","46902504","46636887","97370306","99631112");
$catID_No1 = "579";
$catID_No2 = "521";
$SearchIndex = "VideoGames";
$extras = "ds";
break;
case "PSP";
$item_list = array
("98976817","73249759","104952874","96252069","101417863","95629612","101519004","102345745","102652252","101984241");
$catID_No1 = "579";
$catID_No2 = "521";
$SearchIndex = "VideoGames";
$extras = "psp";
break;
case "Blu-Ray";
$item_list = array
("98976820","50950654","49946570","96257195","50950658","47852792","96545324","96252716","100813451","45679493");
$catID_No1 = "550";
$catID_No2 = "235";
$SearchIndex = "DVD";
$extras = "bluray";
break;
case "Books";
$item_list = array
("81050227","47151180","47645153","47387301","42161543","40115593","46780638","100493106","47392007","100493117");
$catID_No1 = "230";
$catID_No2 = "538";
$SearchIndex = "Books";
$extras = "Hardback";
break;
}

echo "<h1>$category</h1>";

foreach($item_list as $product)
{

$oRefineBy = new stdClass();
$oRefineBy -> iId = 4;
$oRefineBy -> sName = 'Category';
$oRefineByDefinition = new stdClass();
$oRefineByDefinition -> sId = $catID_No1;
$oRefineByDefinition -> sName = '';
$oRefineByDefinition2 = new stdClass();
$oRefineByDefinition2 -> sId = $catID_No2;
$oRefineByDefinition2 -> sName = '';
$oRefineBy -> oRefineByDefinition = array($oRefineByDefinition, $oRefineByDefinition2);
$returnedcolumns = array(iId,sName,sDescription,iMerchantId,iCategoryId,sAwThumbUrl,sMerchantImageUrl,fRrpPrice);

$aParams = array("iProductId" => $product, "sColumnToReturn" => $returnedcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getProduct', $aParams);

if($oResponse->oProduct->sName <> "")
{
$prodID = $oResponse->oProduct->iId;
$prod_title = str_replace("&amp;", "&", $oResponse->oProduct->sName);
$short_title = preg_replace("/:|'|\s*\(.*\)|\s*\[.*\]/U", "", $prod_title);
if(isset($oResponse->oProduct->sAwThumbUrl) && $oResponse->oProduct->sAwThumbUrl <> "")
{
$thumb_img = $oResponse->oProduct->sAwThumbUrl;
}
elseif(isset($oResponse->oProduct->sMerchantThumbUrl) && $oResponse->oProduct->sMerchantThumbUrl <> "")
{
$thumb_img = $oResponse->oProduct->sMerchantThumbUrl;
}
else
{
$thumb_img = "images/noimg.gif";
}
#$link = htmlspecialchars($oResponse->oProduct->sAwDeepLink);
$link = htmlspecialchars($oResponse->oProduct->sAwDeepLink);
$price = $oResponse->oProduct->fPrice;
$merchantid = $oResponse->oProduct->iMerchantId;
$desc = $oResponse->oProduct->sDescription;
$rrp = "";
$img = "";
$data = "";
$alternative = "";
$director = "";
$rating = "";
$runningtime = "";
$priceLo = "";
$priceHi = "";
$priceDiff = "";
$percentage ="";
$cd_ASIN = "";

if($merchantid == "1418")//FOR PLAY.COM
{
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#/(Films|Games)/(\w+?)\.flv\&#', $input, $match))
{
$cd_ASIN = $match[1]."/".$match[2];
}
}

if($merchantid == "2547" || $merchantid == "2548")//FOR The Hut and Sendit
{
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#theVideoFile =.+?/trailers/([\d\-]+?)\.flv#', $input, $match))
{
$cd_ASIN = $match[1];
}
}



#use amazon to get larger img and rrp backup
$obj = aws_signed_request("co.uk",
array("AssociateTag" => "kernconn-21",
"Operation" => "ItemSearch",
"Keywords" => $short_title." ".$extras,
"SearchIndex" => $SearchIndex,
"ResponseGroup" => "Large"),
$public_key, $private_key);

$count = 1;
foreach($obj->Items->Item as $item)
{
if($count <= 1)
{
$merchantname = "AM01";
$rating = $item->ItemAttributes->AudienceRating;
$director = $item->ItemAttributes->Director;
$runningtime = $item->ItemAttributes->RunningTime;

if($item->MediumImage->URL)
{
$img = $item->MediumImage->URL;
}
elseif($item->LargeImage->URL)
{
$img = $item->LargeImage->URL;
}
elseif($oResponse->oProduct->sMerchantImageUrl)
{
$img = $oResponse->oProduct->sMerchantImageUrl;
}
else
{
$img = "No Image";
}

switch($category)
{
case "DVD";
foreach($item->ItemAttributes->Actor as $actor)
{
$data = str_replace("'", "'", $data);
$data = $data." ".$actor;
}
break;
case "CD";
$data = $item->ItemAttributes->Artist;

#GET ALBUM ASIN FOR WIDGET
//STEP 1 THE MAIN SEARCH
$obj = aws_signed_request("co.uk",
array("AssociateTag" => "kernconn-21",
"Operation" => "ItemSearch",
"Keywords" => $short_title,
"SearchIndex" => "Music",
#"Artist" => "cheryl cole",
"ResponseGroup" => "Large"),
$public_key, $private_key);

$count = 1;
foreach($obj->Items->Item as $item)
{
if((isset($item->ItemAttributes->Title)) && $count <= 1)
{
$merchantname = "AM01";
$productPrice = $item->Offers->Offer->OfferListing->Price->FormattedPrice;
$productPrice = trim($productPrice,'');
$link = htmlspecialchars($item->DetailPageURL);
$image = $item->MediumImage->URL;
$title = $item->ItemAttributes->Title;
$ASIN = $item->ASIN;
$count ++;
}
}

//STEP 2 ItemLookup on the CD's ASIN
$obj = aws_signed_request("co.uk",
array("AssociateTag" => "kernconn-21",
"Operation" => "ItemLookup",
"ItemId" => $ASIN,
"RelationshipType" => "AuthorityTitle",
"ResponseGroup" => "RelatedItems"),
$public_key, $private_key);

foreach($obj->Items->Item->RelatedItems->RelatedItem->Item as $result)
{
$cd = $result->ASIN;
}

//STEP 3 GETTING ALL THE VERSION ASINS OF THE CD
$obj = aws_signed_request("co.uk",
array("AssociateTag" => "kernconn-21",
"Operation" => "ItemLookup",
"ItemId" => $cd,
"RelationshipType" => "AuthorityTitle",
"ResponseGroup" => "RelatedItems"),
$public_key, $private_key);

$count = 1;

foreach($obj->Items->Item->RelatedItems->RelatedItem as $versions)
{
$obj = aws_signed_request("co.uk",
array("AssociateTag" => "kernconn-21",
"Operation" => "ItemLookup",
"ItemId" => $versions->Item->ASIN,
"ResponseGroup" => "Large"),
$public_key, $private_key);

foreach($obj->Items->Item->ASIN as $mp3)
{
$obj = aws_signed_request("co.uk",
array("AssociateTag" => "kernconn-21",
"Operation" => "ItemLookup",
"ItemId" => $mp3,
"ResponseGroup" => "Large"),
$public_key, $private_key);

foreach($obj->Items->Item->ASIN as $item)
{
if($obj->Items->Item->ItemAttributes->Binding == "MP3 Download")
{
print $obj->Items->Item->ASIN;//GET THE MP3 ALBUM ASIN FOR MP3 WIDGET
$cd_ASIN = $obj->Items->Item->ASIN;
}
}
}
$count++;
}

break;
case "Xbox 360";
$data = $item->ItemAttributes->Platform;
break;
case "PS3";
$data = $item->ItemAttributes->Platform;
break;
case "Wii";
$data = $item->ItemAttributes->Platform;
break;
case "DS";
$data = $item->ItemAttributes->Platform;
break;
case "PSP";
$data = $item->ItemAttributes->Platform;
break;
case "Blu-Ray";
foreach($item->ItemAttributes->Actor as $actor)
{
$data = str_replace("'", "'", $data);
$data = $data." ".$actor;
}
break;
case "Books";
$data = $item->ItemAttributes->Author;
break;
}

$actors = "";
$listprice = $item->ItemAttributes->ListPrice->FormattedPrice;
$listprice = str_replace("","",$listprice);
$releasedate = $item->ItemAttributes->ReleaseDate;

}
$count ++;
}

#get rrp
if($oResponse->oProduct->fRrpPrice <> "0.00")
{
$rrp = $oResponse->oProduct->fRrpPrice;
}
else
{
$rrp = $listprice;
}

#GET MERCHANT NAME
$merchantcolumns = array(iId,sName,sClickThroughUrl);
$merchantrows = array("sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getMerchant', $merchantrows);

foreach($oResponse->oMerchant as $merchID)
{
if($merchID->iId == $merchantid)
{
$merchName = $merchID->sName;
$merchLink = htmlspecialchars($merchID->sClickThroughUrl);
}
}

echo $short_title." --> ".$prodID;
echo "<br />";

#$insert ="INSERT INTO category_data3(prodID,ASIN,prodName,short_prodName,alternative_prodName,prodthumbIMG,prodIMG,prodLin k,prodDesc,prodRelease,prodXtra,prodRating,prodRunningtime,ProdDirector,prodRRP,prodPrice,category,m erchName,merchLink,priceHi,priceLo,priceDiff,percentage) VALUES ('$prodID','$cd_ASIN','$prod_title','$short_title','$alternative_title','$thumb_img','$img','$link', '$desc','$releasedate','$data','$rating','$runningtime','$director','$rrp','$price','$category','$me rchName','$merchLink','$priceLo','$priceHi','$priceDiff','$percentage')";
#$query = mysql_query($insert)or die(mysql_error());
}

//if($oResponse->oProduct->sName == ""
else
{
print $category;
}
}

}
?>
</body>
</html>

can anyone help me with this strage problem?

p.s i've commented out the adding to db part :)

cheers
Luke

masterofollies
03-26-2010, 02:31 AM
Try this to see what happens


echo "$short_title <br /> $prodID";

LJackson
03-26-2010, 02:41 AM
hi mate,

still nothing unfortunatly :(

cheers

LJackson
03-26-2010, 03:52 AM
ok i have stripped it right down and started rebuilding it piece by piece.

and i got so far but this seemed to stop the data displaying

elseif($merchantid == "2547" || $merchantid == "2548")//FOR The Hut and Sendit
{
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#theVideoFile =.+?/trailers/([\d\-]+?)\.flv#', $input, $match))
{
$cd_ASIN = $match[1];
}
}

any reason why it should???

cheers
Luke

MattF
03-26-2010, 04:12 AM
The page appears fine. Have you considered that it could just be lagging due to the connection to the remote server? The page can't finish processing until that remote information has been received and processed.

LJackson
03-26-2010, 12:32 PM
hi mate,

the page is currently working because i have rebuilt the page adding bits at a time to try and figure out where the problem lies, and i got so far but when adding the above code it stopped displaying the data on screen? which is odd because you and i know that code works, so im not sure why it would stop the page from loading.

very strange!
cheer mate

LJackson
03-26-2010, 12:37 PM
it doesnt like the or part of this code???

elseif($merchantid == "2547" || $merchantid == "2548")//FOR The Hut and Sendit

this works and the data is still shown on my page

elseif($merchantid == "2547")

so why not the first bit of code?

also if i add it seperatly like so

elseif($merchantid == "2547")//FOR The Hut
{
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#theVideoFile =.+?/trailers/([\d\-]+?)\.flv#', $input, $match))
{
$cd_ASIN = $match[1];
}
}

elseif($merchantid == "2548")//FOR Sendit
{
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#theVideoFile =.+?/trailers/([\d\-]+?)\.flv#', $input, $match))
{
$cd_ASIN = $match[1];
}
}

the page fails to load?

i also tried a switch for the merchantid like so

switch($merchantid)
{
case "1418";//play.com
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#/(Films|Games)/(\w+?)\.flv\&#', $input, $match))
{
$cd_ASIN = $match[1]."/".$match[2];
}
break;

case "2547";//the hut.com
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#theVideoFile =.+?/trailers/([\d\-]+?)\.flv#', $input, $match))
{
$cd_ASIN = $match[1];
}
break;

case "2548";//send it.com
$url = htmlspecialchars_decode($link);
$input = file_get_contents($url);

if (preg_match('#theVideoFile =.+?/trailers/([\d\-]+?)\.flv#', $input, $match))
{
$cd_ASIN = $match[1];
}
break;

}


but nothing?

this is very strange.

LJackson
03-26-2010, 02:24 PM
ok part of my current problem is that my call allowance for the api has run out so i cant do anymore testing till this evening :(

cheers



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum