Jump to content

Display results not working


oracle765

Recommended Posts

It looks like it's told you already what you need to do..

 

Without looking at your code, I would assume you're doing something like this:

 

$arr = array( /* lots of data*/);
echo json_encode($arr);

 

The error message is asking for the header, so on the line directly before your echo, you need to add

 

header('Content-Type: application/json');

 

Hope that helps.

Denno

Link to comment
Share on other sites

You are not accessing their api correctly. The url you are using is for setting up the api parameters.

 

With these parameters you need to create a session with a POST request. To do this you'll need to use cURL. Their api will then the return a session, which you'll use to retrieve the data.

// get the api parametures from setup url
$apiParamsUrl = "http://www.skyscanneraffiliate.net/portal/en-GB/UK/LivePricing/TestHarness?apikey=cc379434454338361714672782744594&country=GB&currency=GBP&locale=en-GB&originplace=edi&destinationplace=lon&outbounddate=2014-01-31&inbounddate=2014-02-07&adults=1&children=0&infants=0&locationschema=iata&cabinclass=economy";
$apiParamsStr = parse_url($apiUrl, PHP_URL_QUERY); // get the query string parametures
parse_str($apiParamsStr, $apiParamsArray); // parse into an array

// the api url. First we need to request for a session
$apiSessionUrl = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0';

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $apiSessionUrl);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json')); // make api return json data
curl_setopt($ch,CURLOPT_POST, count($apiParamsArray)); // set how many fiels
curl_setopt($ch,CURLOPT_POSTFIELDS, $apiParamsStr);    // set the fields

// caputre the headers
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);

//execute post
$response = curl_exec($ch);

// get the headers
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);

//close connection
curl_close($ch);

// get the api session url
preg_match('~Location: ([^\s]+)~', $header, $matches);
$apiSessionUrl = $matches[1];

// add on the api key for the session
$apiSessionUrl .= '?apiKey=' . $apiParamsArray['apikey'];

// get the json data
$data = file_get_contents($apiSessionUrl);

// decode the json
$array = json_decode($data);

// dump json array
printf('<pre>Poll Data  %s</pre>', print_r($array, true));
Edited by Ch0cu3r
Link to comment
Share on other sites

if tried

 

foreach ($array['Itineraries']['PricingOptions'] as $arr) {

 

echo "<b> Price </b> " .$arr['Price'], " <br> price </b>,$arr['Price'] ?> <br />

<?php

}

?>

 

to try and echo out the Price twice but I just get an error  saying

 

Fatal Error: Cannot use object of type stdClass as array in /home/etc/etc/skyscanner.php

Link to comment
Share on other sites

Try setting json_decode to    $array = json_decode($data, true);

 

You'd loop over the itinerary price options using

foreach ($array['Itineraries'] as $Itineraries) {
	foreach($Itineraries['PricingOptions'] as $Option) {
              echo "<b> Price </b> " .$Option['Price'], " <br> price </b>",$Option['Price'] ,"<br />";
        }
}
Edited by Ch0cu3r
Link to comment
Share on other sites

thanks again but it still comes up with that fatal error for some reason!

 

I have included my whole page just incase I am missing something as you can see at www.compareandchoose.com.au/skyscanner.php my end goal is to provide an itinery to the users so they can go and book, but the out put in that array is a bit confusing for me to try and present nicely to them

 

 

skyscanner.php

Link to comment
Share on other sites

For displaying the Legs,  Carriers and Places you don't need the secondary foreach loop. Also $Option['Agents'] contains an array of agents, to display these implode them.

		//Itineraries
		foreach ($array['Itineraries'] as $Itineraries) {
		
			foreach($Itineraries['PricingOptions'] as $Option) {
              	echo "<b> Price </b> " .implode(',', $Option['Agents']), " <br> price </b>",$Option['Price'] ,"<br />";
        	}
		}
		
		//Legs
		foreach ($array['Legs'] as $Leg) {
		
			echo "<b> Departure </b> " .$Leg['Departure'], " <br> <b>Arrival </b>",$Leg['Arrival'] ,"<br />";
		}
		
		//Carriers
		foreach ($array['Carriers'] as $Carrier) {
		
				echo "<b> Name </b> " .$Carrier['Name'], " <br> Image </b>",$Carrier['ImageUrl'] ,"<br />";
		}
		
		//Places
		foreach ($array['Places'] as $Place) {
		
			echo "<b> Code </b> " .$Place['Code'], " <br> Name </b>",$Place['Name'] ,"<br />";
		}

Also checkout the code I sent you in PM

Edited by Ch0cu3r
Link to comment
Share on other sites

hi CH0cu3r

 

Thanks for that as it now extracts results, but as you can see it just produces lines and lines of prices, airlines etc,  how do you actually know which Agent, flight, airline, price etc is linked to which

 

EG Image, British airways, from, to, departure, arrival, price etc <br>

 

      Image, Air Lingus, from, to, departure, arrival, price etc <br> and so on

 

again thanks in advance you have been a massive help in figuring out my array problems which I am totally new to

Link to comment
Share on other sites

The Itinerary array contains a list of flights. Each flight contains a PricesOption array which lists the booking agents and their price.  Each agent has their own unique id, to get the agent name/image you need to look up the agent id within the $array['Agents'] array.

 

To get the flight information you need to look up the OutboundLegId and InboundLegId within the $array['Legs'] array. This will return an array of information about depature and arrival airports. The OriginStation (departure) and DestinationStation (arrival) keys return the airport ids. To the get the airport names you need to look up these ids within the $array['Places'] array.

 

You'll also get the flight carrier from the $array['Legs'] array, again each carrier has their own unique id which you you need to loop up within the $array['Carriers'] array.

 

 

.

Edited by Ch0cu3r
Link to comment
Share on other sites

ok thanks just on the last part you say

 

You'll also get the flight carrier from the $array['Legs'] array, again each carrier has their own unique id which you need to loop up within the $array['Carriers'] array

 

could you explain what you mean by loop up with that array, sorry to be a pain but arrays are my weekpoint lol

 

 

thanks again your an excellent role model to this forum

Link to comment
Share on other sites

By look up I mean loop through the array of carriers within $array['Carriers']. You'd check to see if the Id matches the carrier for the flight Id. 

 

The easiest way I found to do this was to create a function. It'll extract the Agents, Carriers, Legs and Places arrays. It'll then loop through these arrays setting the Id as the key for each item. This makes looking up the ids for Agents, Carriers, Legs and Places arrays alot easier as you can just pass in the necessary id to get their data.

 

Example code for getting the agent  names

$Agents   = extractItem($array, 'Agents');   // get array of agents
//...

foreach ($array['Itineraries'] as $Itineraries) {
        foreach($Itineraries['PricingOptions'] as $Option) {
             echo "<b> Agents: </b> ";

             // loop over agents for current priceOption
             foreach($Option['agents'] as $agentId) {
                  echo $Agents[ $agentId ]['Name']. ', '; // echo the agent name that matches agentId.
             }
               
             echo " <br> price </b>",$Option['Price'] ,"<br />";
       }
}

The code for extractItem() is

function extractItem(&$array, $itemkey)
{
	$data = array();
        
	foreach($array[$itemKey] as $item)
	{
              $Id = $item['Id'];  // get the id
              unset($item['Id']); // remove the id from item array
              $data[$Id] = $item; // set id as the key
	}

	unset($array[$itemKey]); // remove item from array.

	return $data; // return the new item array
}
Edited by Ch0cu3r
Link to comment
Share on other sites

  • 3 weeks later...
[categories] => Array
        (
            [intActualCategoryCount] => 1
            [category] => Array
                (
                    [0] => Array
                        (
                            [name] => Washing Machines
                            [categoryURL] => http://www.au.shopping.com/washing-machines/washing-machine/products?oq=washing_machine&linkin_id=8084586
                            [items] => Array
                                (
                                    [matchedItemCount] => 92
                                    [returnedItemCount] => 5
                                    [pageNumber] => 1
                                    [item] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [offer] => Array
                                                        (
                                                            [id] => PxR1LOEEcM0Vu81EqNbqAw==
                                                            [used] => 
                                                            [featured] => 
                                                            [smartBuy] => 
                                                            [name] => 5.5kg LG Top Load Washing Machine WTH550
                                                            [description] => Best value is guaranteed when you buy the 5.5kg LG Top Load Washing Machine WTH550 from Appliances Online. Trusted by over 300,000 customers, Appliances Online is the largest online appliance retailer in Australia.
                                                            [manufacturer] => LG
                                                            [imageList] => Array
                                                                (
                                                                    [image] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [sourceURL] => http://di61.shoppingshadow.com/images/di/50/78/52/314c4f4545634d305675383145714e62714177-100x100-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=1&pr=1&lks=145181&fks=145181
                                                                                    [height] => 100
                                                                                    [width] => 100
                                                                                    [available] => 1
                                                                                )

                                                                            [1] => Array
                                                                                (
                                                                                    [sourceURL] => http://di61.shoppingshadow.com/images/di/50/78/52/314c4f4545634d305675383145714e62714177-200x200-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=1&pr=1&lks=145181&fks=145181
                                                                                    [height] => 200
                                                                                    [width] => 200
                                                                                    [available] => 1
                                                                                )

                                                                            [2] => Array
                                                                                (
                                                                                    [sourceURL] => http://di61.shoppingshadow.com/images/di/50/78/52/314c4f4545634d305675383145714e62714177-300x300-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=1&pr=1&lks=145181&fks=145181
                                                                                    [height] => 300
                                                                                    [width] => 300
                                                                                    [available] => 1
                                                                                )

                                                                            [3] => Array
                                                                                (
                                                                                    [sourceURL] => http://img.shoppingshadow.com/sc/ds/no_image_100X100.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=1&pr=1&lks=145181&fks=145181
                                                                                    [height] => 400
                                                                                    [width] => 400
                                                                                    [available] => 
                                                                                )

                                                                            [4] => Array
                                                                                (
                                                                                    [sourceURL] => http://di61.shoppingshadow.com/images/di/50/78/52/314c4f4545634d305675383145714e62714177-263x370-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=1&pr=1&lks=145181&fks=145181
                                                                                    [height] => 370
                                                                                    [width] => 263
                                                                                    [available] => 1
                                                                                )

                                                                        )

                                                                )

                                                            [stockStatus] => in-stock
                                                            [basePrice] => Array
                                                                (
                                                                    [value] => 585.00
                                                                    [currency] => AUD
                                                                )

                                                            [tax] => Array
                                                                (
                                                                    [value] => 0.00
                                                                    [currency] => AUD
                                                                )

                                                            [shippingCost] => Array
                                                                (
                                                                    [value] => 0.00
                                                                    [currency] => AUD
                                                                )

                                                            [totalPrice] => Array
                                                                (
                                                                    [value] => 585.00
                                                                    [currency] => AUD
                                                                )

                                                            [originalPrice] => Array
                                                                (
                                                                    [value] => 829.00
                                                                    [currency] => AUD
                                                                )

                                                            [offerURL] => http://statTest.dealtime.com/DealFrame/DealFrame.cmp?bm=130&BEFID=1897&aon=%5E1&MerchantID=427149&crawler_id=1905980&dealId=PxR1LOEEcM0Vu81EqNbqAw%3D%3D&url=http%3A%2F%2Fad.doubleclick.net%2Fclk%3B272924216%3B98885278%3Bd%3Fhttp%3A%2F%2Fwww.appliancesonline.com.au%2F55kg-lg-top-load-washing-machine-wth550%2F%3Futm_source%3Dshoppingcom%26utm_medium%3Dcse%26utm_campaign%3Dtop_load_washing_machines%26utm_content%3DWTH550&linkin_id=8084586&Issdt=140217064107&searchID=v3.46899dc104de95cd9ad5&DealName=5.5kg+LG+Top+Load+Washing+Machine+WTH550&dlprc=585.0&AR=1&NG=1&NDP=2&PN=1&ST=7&FPT=DSP&NDS=&NMS=&MRS=&PD=&brnId=14305&IsFtr=0&IsSmart=0&op=&CM=&RR=1&IsLps=0&code=&acode=217&category=&HasLink=&ND=&MN=&GR=&lnkId=&SKU=WTH550
                                                            [store] => Array
                                                                (
                                                                    [name] => Appliances Online
                                                                    [logo] => Array
                                                                        (
                                                                            [sourceURL] => http://img.shopping.com/cctool/merch_logos/427149.gif
                                                                            [height] => 31
                                                                            [width] => 88
                                                                            [available] => 1
                                                                        )

                                                                    [phoneNumber] => 1300 000 500
                                                                    [ratingInfo] => Array
                                                                        (
                                                                            [reviewCount] => 81
                                                                            [rating] => 4.74
                                                                            [ratingImage] => Array
                                                                                (
                                                                                    [sourceURL] => http://img.shopping.com/sc/mr/sdc_checks_45.gif
                                                                                    [height] => 18
                                                                                    [width] => 91
                                                                                )

                                                                            [reviewURL] => http://www.au.shopping.com/xMR-store_appliances_online_4114784~MRD-427149~S-1~linkin_id-8084586
                                                                        )

                                                                    [countryFlag] => Array
                                                                        (
                                                                            [countryCode] => AU
                                                                            [sourceURL] => http://img.shopping.com/sc/glb/flag/AU.gif
                                                                            [height] => 11
                                                                            [width] => 18
                                                                        )

                                                                    [id] => 427149
                                                                    [trusted] => 1
                                                                    [authorizedReseller] => 
                                                                )

                                                            [cpc] => 0.76
                                                            [categoryId] => 1897
                                                            [sku] => WTH550
                                                            [mpn] => WTH550
                                                        )

                                                )

                                            [1] => Array
                                                (
                                                    [product] => Array
                                                        (
                                                            [name] => Simpson SWT554 Washing Machine
                                                            [fullDescription] => SWT554 Simpson Eziset Top Load 5.5kg Simpson Eziset Top Load Washing Machine 5.5kg Key Benefits Donât wait for a wash to finish All EZI Set models feature a time remaining display so you donât have to wait around for a wash to finish. You can better plan your day and get on with things youâd rather do. Soak in the tub With the Soak feature, you no longer have to fill the laundry tub or bucket full of soapy water to soak clothes.
                                                            [onSale] => 
                                                            [onSalePercentOff] => 0
                                                            [freeShipping] => 1
                                                            [images] => Array
                                                                (
                                                                    [image] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [sourceURL] => http://di3-2.shoppingshadow.com/pi/i.ebayimg.com/00/$T2eC16NHJG!FFm)BSeoSBSL!B(WBoQ~~_32-100x100-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=2&c=36&l=8084586&r=2&pr=2&pid=120196545&lks=142107&fks=142107&pdid=6F6pQ7Xs2Fq6A3HPubPXYQ%3D%3D
                                                                                    [height] => 100
                                                                                    [width] => 100
                                                                                    [available] => 1
                                                                                )

                                                                            [1] => Array
                                                                                (
                                                                                    [sourceURL] => http://di3-2.shoppingshadow.com/pi/i.ebayimg.com/00/$T2eC16NHJG!FFm)BSeoSBSL!B(WBoQ~~_32-200x200-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=2&c=36&l=8084586&r=2&pr=2&pid=120196545&lks=142107&fks=142107&pdid=6F6pQ7Xs2Fq6A3HPubPXYQ%3D%3D
                                                                                    [height] => 200
                                                                                    [width] => 200
                                                                                    [available] => 1
                                                                                )

                                                                            [2] => Array
                                                                                (
                                                                                    [sourceURL] => http://di3-2.shoppingshadow.com/pi/i.ebayimg.com/00/$T2eC16NHJG!FFm)BSeoSBSL!B(WBoQ~~_32-300x300-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=2&c=36&l=8084586&r=2&pr=2&pid=120196545&lks=142107&fks=142107&pdid=6F6pQ7Xs2Fq6A3HPubPXYQ%3D%3D
                                                                                    [height] => 300
                                                                                    [width] => 300
                                                                                    [available] => 1
                                                                                )

                                                                            [3] => Array
                                                                                (
                                                                                    [sourceURL] => http://di3-2.shoppingshadow.com/pi/i.ebayimg.com/00/$T2eC16NHJG!FFm)BSeoSBSL!B(WBoQ~~_32-400x400-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=2&c=36&l=8084586&r=2&pr=2&pid=120196545&lks=142107&fks=142107&pdid=6F6pQ7Xs2Fq6A3HPubPXYQ%3D%3D
                                                                                    [height] => 400
                                                                                    [width] => 400
                                                                                    [available] => 1
                                                                                )

                                                                            [4] => Array
                                                                                (
                                                                                    [sourceURL] => http://di3-2.shoppingshadow.com/pi/i.ebayimg.com/00/$T2eC16NHJG!FFm)BSeoSBSL!B(WBoQ~~_32-509x799-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=2&c=36&l=8084586&r=2&pr=2&pid=120196545&lks=142107&fks=142107&pdid=6F6pQ7Xs2Fq6A3HPubPXYQ%3D%3D
                                                                                    [height] => 799
                                                                                    [width] => 509
                                                                                    [available] => 1
                                                                                )

                                                                        )

                                                                )

                                                            [rating] => Array
                                                                (
                                                                    [reviewCount] => 0
                                                                )

                                                            [minPrice] => Array
                                                                (
                                                                    [value] => 449.00
                                                                )

                                                            [maxPrice] => Array
                                                                (
                                                                    [value] => 579.00
                                                                )

                                                            [productOffersURL] => http://www.au.shopping.com/simpson-swt554/prices~linkin_id-8084586
                                                            [productSpecsURL] => http://www.au.shopping.com/simpson-swt554/info~linkin_id-8084586
                                                            [offers] => Array
                                                                (
                                                                    [matchedOfferCount] => 2
                                                                    [returnedOfferCount] => 0
                                                                    [pageNumber] => 1
                                                                )

                                                            [numStores] => 2
                                                            [id] => 120196545
                                                        )

                                                )

                                            [2] => Array
                                                (
                                                    [offer] => Array
                                                        (
                                                            [id] => c2JUMh6N-NSFhASPgKrMCQ==
                                                            [used] => 
                                                            [featured] => 
                                                            [smartBuy] => 
                                                            [name] => 6.5kg Top Load LG Washing Machine WTH650
                                                            [description] => Best value is guaranteed when you buy the LG WM TL 6.5KG DD 4STAR 10YR WARNT from Appliances Online. Trusted by over 300,000 customers, Appliances Online is the largest online appliance retailer in Australia.
                                                            [manufacturer] => LG
                                                            [imageList] => Array
                                                                (
                                                                    [image] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [sourceURL] => http://di64.shoppingshadow.com/images/di/63/32/4a/554d68364e2d4e534668415350674b724d4351-100x100-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=3&pr=3&lks=142107&fks=142107
                                                                                    [height] => 100
                                                                                    [width] => 100
                                                                                    [available] => 1
                                                                                )

                                                                            [1] => Array
                                                                                (
                                                                                    [sourceURL] => http://di64.shoppingshadow.com/images/di/63/32/4a/554d68364e2d4e534668415350674b724d4351-200x200-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=3&pr=3&lks=142107&fks=142107
                                                                                    [height] => 200
                                                                                    [width] => 200
                                                                                    [available] => 1
                                                                                )

                                                                            [2] => Array
                                                                                (
                                                                                    [sourceURL] => http://di64.shoppingshadow.com/images/di/63/32/4a/554d68364e2d4e534668415350674b724d4351-300x300-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=3&pr=3&lks=142107&fks=142107
                                                                                    [height] => 300
                                                                                    [width] => 300
                                                                                    [available] => 1
                                                                                )

                                                                            [3] => Array
                                                                                (
                                                                                    [sourceURL] => http://img.shoppingshadow.com/sc/ds/no_image_100X100.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=3&pr=3&lks=142107&fks=142107
                                                                                    [height] => 400
                                                                                    [width] => 400
                                                                                    [available] => 
                                                                                )

                                                                            [4] => Array
                                                                                (
                                                                                    [sourceURL] => http://di64.shoppingshadow.com/images/di/63/32/4a/554d68364e2d4e534668415350674b724d4351-259x370-0-0.jpg?rqid=v3.46899dc104de95cd9ad5&rqt=SRS&a=1&c=36&l=8084586&r=3&pr=3&lks=142107&fks=142107
                                                                                    [height] => 370
                                                                                    [width] => 259
                                                                                    [available] => 1
                                                                                )

                                                                        )

                                                                )

                                                            [stockStatus] => in-stock
                                                            [basePrice] => Array
                                                                (
                                                                    [value] => 599.00
                                                                    [currency] => AUD
                                                                )

                                                            [tax] => Array
                                                                (
                                                                    [value] => 0.00
                                                                    [currency] => AUD
                                                                )

                                                            [shippingCost] => Array
                                                                (
                                                                    [value] => 0.00
                                                                    [currency] => AUD
                                                                )

                                                            [totalPrice] => Array
                                                                (
                                                                    [value] => 599.00
                                                                    [currency] => AUD
                                                                )

                                                            [originalPrice] => Array
                                                                (
                                                                    [value] => 919.00
                                                                    [currency] => AUD
                                                                )

                                                            [offerURL] => http://statTest.dealtime.com/DealFrame/DealFrame.cmp?bm=130&BEFID=1897&aon=%5E1&MerchantID=427149&crawler_id=1905980&dealId=c2JUMh6N-NSFhASPgKrMCQ%3D%3D&url=http%3A%2F%2Fad.doubleclick.net%2Fclk%3B272924216%3B98885278%3Bd%3Fhttp%3A%2F%2Fwww.appliancesonline.com.au%2F65kg-top-load-lg-washing-machine-wth650%2F%3Futm_source%3Dshoppingcom%26utm_medium%3Dcse%26utm_campaign%3Dtop_load_washing_machines%26utm_content%3DWTH650&linkin_id=8084586&Issdt=140217064107&searchID=v3.46899dc104de95cd9ad5&DealName=6.5kg+Top+Load+LG+Washing+Machine+WTH650&dlprc=599.0&AR=3&NG=1&NDP=2&PN=1&ST=7&FPT=DSP&NDS=&NMS=&MRS=&PD=&brnId=14305&IsFtr=0&IsSmart=0&op=&CM=&RR=2&IsLps=0&code=&acode=217&category=&HasLink=&ND=&MN=&GR=&lnkId=&SKU=WTH650
                                                            [store] => Array
                                                                (
                                                                    [name] => Appliances Online
                                                                    [logo] => Array
                                                                        (
                                                                            [sourceURL] => http://img.shopping.com/cctool/merch_logos/427149.gif
                                                                            [height] => 31
                                                                            [width] => 88
                                                                            [available] => 1
                                                                        )

                                                                    [phoneNumber] => 1300 000 500
                                                                    [ratingInfo] => Array
                                                                        (
                                                                            [reviewCount] => 81
                                                                            [rating] => 4.74
                                                                            [ratingImage] => Array
                                                                                (
                                                                                    [sourceURL] => http://img.shopping.com/sc/mr/sdc_checks_45.gif
                                                                                    [height] => 18
                                                                                    [width] => 91
                                                                                )

                                                                            [reviewURL] => http://www.au.shopping.com/xMR-store_appliances_online_4114784~MRD-427149~S-1~linkin_id-8084586
                                                                        )

                                                                    [countryFlag] => Array
                                                                        (
                                                                            [countryCode] => AU
                                                                            [sourceURL] => http://img.shopping.com/sc/glb/flag/AU.gif
                                                                            [height] => 11
                                                                            [width] => 18
                                                                        )

                                                                    [id] => 427149
                                                                    [trusted] => 1
                                                                    [authorizedReseller] => 
                                                                )

                                                            [cpc] => 0.76
                                                            [categoryId] => 1897
                                                            [sku] => WTH650
                                                            [mpn] => WTH650
                                                        )

                                                )

Hey Ch0cu3r hope your keeping ok

 

Im really stuck again with these arrays lol how do I drill down in this array,this might be simple to you but its very complex for me

 

I have attached the data its extracted so far

 

what I am looking to pull out is the

 

description, manufacturer, the store name who sells it EG appliances online, image of the item and logo of the store etc, your intelligent enough so you will know what I mean.

 

 

 

thanks in advance

alan

Link to comment
Share on other sites

print_r($json_arr);

		foreach ($json_arr ['categories'] as $categories) 
		{		
			foreach($categories['category'] as $category) 
			{
				echo "<b> Link </b>" .$category['categoryURL'] ,"<br/>";
				 
				foreach($category['item'] as $Option) 
				{
              	echo "<b> Name </b> " .implode(',', $Option['name']), " <br> manufacturer </b>",$Option['manufacturer'] ,"<br />";
				}
        	}
		}

PS ive tried this but its returning nothing

Edited by oracle765
Link to comment
Share on other sites

$category['item'] will contain a sub array, either offer or product. You need to loop through this sub array to get the products info

 

Try

foreach ($json_arr['categories'] as $categories) 
{		
    foreach($categories['category'] as $category) 
    {
        echo "<b> Link </b>" .$category['categoryURL'] ,"<br/>";
		 
        foreach($category['item'] as $item)
        {
             // get the sub array key
             $key = key($item);

             echo "<p><b> Name </b> " .implode(',', $item[$key]['name']), " <br> manufacturer </b>",$item[$key]['manufacturer'] ,"<p>";

             // get item description, 
             // for offer use description key
             // for product use fullDescription key
             echo "<p><b>Description</b> " . (($key == 'offer') ? $item[$key]['description'] : $item[$key]['fullDescription']) . '</p>';

            // display product images
            echo '<p><b>Images: </b>';
            foreach($item[$key]['imageList']['image'] as $image)
            {
                echo '<img src="'.$image['SourceUrl'].'" />   ';
            }
            echo '</p>

            // the store logo and name
            echo '<p><b>Store: </b> <img src="'$item[key]['store']['logo']['sourceURL']'" /> ' .$item[key]['store']['name'] .'</p>';
            echo '<hr />';
       }
   }
}
Link to comment
Share on other sites

foreach ($json_arr['categories'] as $categories) 
{		
    foreach($categories['category'] as $category) 
    {
        echo "<b> Link </b>" .$category['categoryURL'] ,"<br/>";
		 
        foreach($category['item'] as $item)
        {
             // get the sub array key
             $key = key($item);

             echo "<p><b> Name </b> " .implode(',', $item[$key]['name']), " <br> manufacturer </b>",$item[$key]['manufacturer'] ,"<p>";

             // get item description, 
             // for offer use description key
             // for product use fullDescription key
             echo "<p><b>Description</b> " . (($key == 'offer') ? $item[$key]['description'] : $item[$key]['fullDescription']) . '</p>';

            // display product images
            echo '<p><b>Images: </b>';
            foreach($item[$key]['imageList']['image'] as $image)
            {
                echo '<img src="'.$image['SourceUrl'].'" />   ';
            }
            echo '</p>';

            // the store logo and name
           // echo '<p><b>Store: </b> <img src="' $item[key]['store']['logo']['sourceURL']'" /> ' .$item[key]['store']['name'] '</p>';
            echo '<hr />';
       }
   }
}

Hi again

 

ive tried this today but nothing seems to be coming back again

 

my dreamweaver was showing an error on the second last line of echo code that I commented out because I could not figure it out and I did notice a semi colon missing from an echo statement above which I fixed but its still showing nothing

 

 

here is what I have so far, I think it might be just a formatting error with the " ' etc but not sure

Link to comment
Share on other sites

//THIS ONE WORKS OK

foreach($json_arr ['categories']['category'] as $arr){

    // $arr will be an array of each url data
	echo "<b> Link </b><a href=" .$arr['categoryURL'].">Apple</a>"?><br /><br /><?php 

} 
foreach($json_arr ['categories'] as $categories) 
{		
    foreach($categories ['category'] as $category) 
    {
        echo "<b> Link </b>" .$category['categoryURL'] ,"<br/>";
		/*
        foreach($category['item'] as $item)
        {
             // get the sub array key
             $key = key($item);

             echo "<p><b> Name </b> " .implode(',', $item[$key]['name']), " <br> manufacturer </b>",$item[$key]['manufacturer'] ,"<p>";

             // get item description, 
             // for offer use description key
             // for product use fullDescription key
             echo "<p><b>Description</b> " . (($key == 'offer') ? $item[$key]['description'] : $item[$key]['fullDescription']) . "</p>";

            // display product images 
			
            echo "<p><b>Images: </b>";
            foreach($item[$key]['imageList']['image'] as $image)
            {
                echo "<img src='" .$image['sourceUrl']. "' />   ";
            }
            echo "</p>";
			
            // the store logo and name
            echo "<p><b>Store: </b> <img src='" .$item[key]['store']['logo']['sourceURL']. "' /> " .$item[key]['store']['name']. "</p>";
            echo "<hr />";
       } */
   }
}

Hi ive commented out the inner foreach loops to try and figure out whats going on  but it seems not to work still

 

im a bit confused as the second attachment loop works

 

 

 

 

 

 

Link to comment
Share on other sites

The code I posted was untested. I coded it from looking at array structure you posted. Try the following instead

foreach ($json_arr['categories']['category'] as $category) 
{       
    echo "<b> Link </b>" .$category['categoryURL'] ."<br/><hr /><h2>Products</h2>";
     
    foreach($category['items']['item'] as $item)
    {
         // get the sub array key
         $key = key($item);

         echo "<p><b>Name: </b> " .$item[$key]['name']. " </p>";
         echo "<p><b>Manufacturer: </b>" . (isset($item[$key]['manufacturer']) ? $item[$key]['manufacturer'] : '') . "</p>";

         // get item description, 
         // for offer use description key
         // for product use fullDescription key

         $descriptionKey = ($key == 'offer') ? 'description' : 'fullDescription';
        echo "<p><b>Description</b> " . $item[$key][$descriptionKey] . '</p>';

        // display product images
        echo '<p><b>Images: </b>';

        $imageListKey = ($key == 'offer') ? 'imageList' : 'images';
        foreach($item[$key][$imageListKey]['image'] as $image)
        {
            echo '<img src="'.$image['sourceURL'].'" />   ';
        }
        echo '</p>';

        // the store logo and name
        echo '<p><b>Buy From: </b>';
        if(isset($item[$key]['store']))
        {
            echo '<img src="'.$item[$key]['store']['logo']['sourceURL'].'" /> ' .$item[$key]['store']['name'] .'</p>';
        }
        echo '<hr />';
   }
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.