I am using the PHP specific SOAPClient in order to call for a soap API and get responses.
The problem I have is that I do not manage to get in order the results, neither to extract them.
The code I am using is:
<?php
$wsdl = 'http://portalquery.just.ro/Query.asmx?wsdl';
$client = new SoapClient($wsdl);
$xml_array['numarDosar'] = '10080/3/2013';
$response = $client->CautareDosare2($xml_array);
var_dump($response);
?>
The results I get are:
object(stdClass)#2 (1) { ["CautareDosare2Result"]=> object(stdClass)#3 (1) { ["Dosar"]=> array(2) { [0]=> object(stdClass)#4 (13) { ["parti"]=> object(stdClass)#5 (1) { ["DosarParte"]=> array(3) { [0]=> object(stdClass)#6 (2) { ["nume"]=> string(22) "Mocanu Andrei Cristian" ["calitateParte"]=> string(17) "Recurent Inculpat" } [1]=> object(stdClass)#7 (2) { ["nume"]=> string(21) "Mocanu Răzvan George" ["calitateParte"]=> string(17) "Recurent Inculpat" } [2]=> object(stdClass)#8 (2) { ["nume"]=> string(11) "Mica Marian" ["calitateParte"]=> string(17) "Recurent Inculpat" } } } ["sedinte"]=> object(stdClass)#9 (1) { ["DosarSedinta"]=> object(stdClass)#10 (9) { ["complet"]=> string(26) "S2 Complet urgentă recurs" ["data"]=> string(19) "2013-03-14T00:00:00" ["ora"]=> string(5) "12:00" ["solutie"]=> string(14) "Respins recurs" ["solutieSumar"]=> string(408) "Înc. 82/R/În majoritate :Respinge ca nefondate recursurile declararate de recurenţii inculpaţi Mocanu Andrei Cristian, Mocanu Răzvan George şi Mica Marian. Obligă pe fiecare recurent la câte 300 lei cheltuieli judiciare către stat. Pronunţată în şedinţă publică, azi, 14.03.2013. Opinie separată în sensul admiterii recursurilor şi luării măsurii obligării de a nu părăsi localitatea." ["dataPronuntare"]=> string(19) "2013-03-14T00:00:00" ["documentSedinta"]=> string(33) "incheieremasuripreventivefazadeUP" ["numarDocument"]=> string(7) "82/2013" ["dataDocument"]=> string(19) "2013-03-14T00:00:00" } } ["numar"]=> string(12) "10080/3/2013" ["numarVechi"]=> string(8) "831/2013" ["data"]=> string(19) "2013-03-14T00:00:00" ["institutie"]=> string(21) "CurteadeApelBUCURESTI" ["departament"]=> string(22) "Secţia a II-a penală" ["categorieCaz"]=> string(5) "Penal" ["stadiuProcesual"]=> string(6) "Recurs" ["obiect"]=> string(113) "prelungirea duratei arestării preventive dispuse în cursul urmăririi penale (art. 156 şi următoarele C.p.p.)" ["dataModificare"]=> string(23) "2017-01-18T06:48:34.467" ["categorieCazNume"]=> string(5) "Penal" ["stadiuProcesualNume"]=> string(6) "Recurs" } [1]=> object(stdClass)#11 (14) { ["parti"]=> object(stdClass)#12 (1) { ["DosarParte"]=> array(3) { [0]=> object(stdClass)#13 (2) { ["nume"]=> string(22) "MOCANU ANDREI CRISTIAN" ["calitateParte"]=> string(8) "Inculpat" } [1]=> object(stdClass)#14 (2) { ["nume"]=> string(20) "MOCANU RAZVAN GEORGE" ["calitateParte"]=> string(8) "Inculpat" } [2]=> object(stdClass)#15 (2) { ["nume"]=> string(11) "MICA MARIAN" ["calitateParte"]=> string(8) "Inculpat" } } } ["sedinte"]=> object(stdClass)#16 (1) { ["DosarSedinta"]=> object(stdClass)#17 (9) { ["complet"]=> string(5) "CC1 -" ["data"]=> string(19) "2013-03-12T00:00:00" ["ora"]=> string(5) "23:59" ["solutie"]=> string(12) "Soluţionare" ["solutieSumar"]=> string(311) "În baza prevederilor art. 155 şi urm. C.p.p. dispune prelungirea măsurii arestării preventive a inculpaţilor Mocanu Andrei Cristian, Mocanu Răzvan George şi Mica Marius pe o perioadă de 20 de zile, de la 15.03.2013 - 03.04.2013, inclusiv. Cu recurs. Pronunţată în şedinţă publică azi, 12.03.2013." ["dataPronuntare"]=> string(19) "2013-03-12T00:00:00" ["documentSedinta"]=> string(27) "incheierefinaladezinvestire" ["numarDocument"]=> string(0) "" ["dataDocument"]=> string(19) "2013-03-12T00:00:00" } } ["caiAtac"]=> object(stdClass)#18 (1) { ["DosarCaleAtac"]=> object(stdClass)#19 (3) { ["dataDeclarare"]=> string(19) "2013-03-13T00:00:00" ["parteDeclaratoare"]=> string(37) " MICA MARIAN, MOCANU RAZVAN GEORGE, " ["tipCaleAtac"]=> string(6) "Recurs" } } ["numar"]=> string(12) "10080/3/2013" ["numarVechi"]=> string(0) "" ["data"]=> string(19) "2013-03-11T00:00:00" ["institutie"]=> string(19) "TribunalulBUCURESTI" ["departament"]=> string(22) "Secţia a-II-a Penală" ["categorieCaz"]=> string(5) "Penal" ["stadiuProcesual"]=> string(4) "Fond" ["obiect"]=> string(113) "prelungirea duratei arestării preventive dispuse în cursul urmăririi penale (art. 156 şi următoarele C.p.p.)" ["dataModificare"]=> string(23) "2017-01-18T08:33:50.877" ["categorieCazNume"]=> string(5) "Penal" ["stadiuProcesualNume"]=> string(4) "Fond" } } } }
I tried to explode on the results, also used $response[1]->array and such, nothing works.
<?php
ini_set("display_errors", 1);
$wsdl = 'http://portalquery.just.ro/Query.asmx?wsdl';
$client = new SoapClient($wsdl);
$xml_array['numarDosar'] = '10080/3/2013';
$response = $client->CautareDosare2($xml_array);
$resultArray= json_decode(json_encode($response),true);
$arrayOnfirstKey=$resultArray[key($resultArray)];
$arrayOnSecondKey= $arrayOnfirstKey[key($arrayOnfirstKey)];
echo "<table>";
echo "<tr>";
echo "<td>nume</td>";
echo "<td>CalitateParte</td>";
echo "</tr>";
foreach($arrayOnSecondKey as $value)
{
foreach($value["parti"]["DosarParte"] as $data)
{
echo "<tr>";
echo "<td>" .$data["nume"]."</td>";
echo "<td>" .$data["calitateParte"]."</td>";
echo "</tr>";
}
}
echo "</table>";
Related
I have an array returned from Google Maps, that looks like this:
array(4) {
["destination_addresses"]=> array(4) {
[0]=> string(19) "Walsall WS2 9PS, UK"
[1]=> string(19) "Walsall WS2 9PS, UK"
[2]=> string(19) "Walsall WS2 9PS, UK"
[3]=> string(26) "Wolverhampton WV10 0QP, UK"
}
["origin_addresses"]=> array(1) {
[0]=> string(18) "Stone ST15 0FL, UK"
}
["rows"]=> array(1) {
[0]=> array(1) {
["elements"]=> array(4) {
[0]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "41.9 km"
["value"]=> int(41947)
}
["duration"]=> array(2) {
["text"]=> string(7) "36 mins"
["value"]=> int(2134)
}
["status"]=> string(2) "OK"
}
[1]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "41.9 km"
["value"]=> int(41947)
}
["duration"]=> array(2) {
["text"]=> string(7) "36 mins"
["value"]=> int(2134)
}
["status"]=> string(2) "OK"
}
[2]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "41.9 km"
["value"]=> int(41947)
}
["duration"]=> array(2) {
["text"]=> string(7) "36 mins"
["value"]=> int(2134)
}
["status"]=> string(2) "OK"
}
[3]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "40.9 km"
["value"]=> int(40924)
}
["duration"]=> array(2) {
["text"]=> string(7) "41 mins"
["value"]=> int(2458)
}
["status"]=> string(2) "OK"
}
}
}
}
["status"]=> string(2) "OK"
}
I want to be able to run through the array, and print the destination address and the distance and time values.
This prints the destination addresses ok:
$length=count($properties);
for($a=0;$a<$length;$a++)
{
echo '</br>Index is ' . $a . ' | id is ' . $index[$a] . ' | destination is ' . $properties["destination_addresses"][$a] . ' | time is ';
}
But I can't figure out how to print the rest. I've been banging my head against the wall all night!
Thank you in anticipation.
To loop over all these journeys and print the distance and time for each potential journey, create a foreach loop and then use the $idx to address the subordinate parts of the muleiple arrays
foreach( $destination['destination_addresses'] as $idx => $to ) {
if ( $destination['rows'][0]['elements'][$idx]['status'] == 'OK' ) {
echo 'Going from ' . $destination['origin_addresses'][0];
echo ' To ' . $to;
echo ' Distance ' . $destination['rows'][0]['elements'][$idx]['distance']['text'];
echo ' Duration ' . $destination['rows'][0]['elements'][$idx]['duration']['text'];
} else {
//whatever you do if the status is not OK
}
}
I get response from the server in Simple XML, but I want get to my page only data I need and show this data in html tags. How I can do it?
My request code:
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');
$c = new TopClient;
$c->appkey = '*******';
$c->secretKey = '***************';
$req = new AliexpressAffiliateProductQueryRequest;
$req->setAppSignature("1111");
$req->setFields("sale_price");
$req->setKeywords("car");
$req->setMaxSalePrice(300);
$req->setMinSalePrice(150);
$req->setPageNo(1);
$req->setPageSize(2);
$req->setSort("SALE_PRICE_ASC");
$req->setTargetCurrency("USD");
$req->setTargetLanguage("en");
$req->setTrackingId("trackID");
echo "<pre>";
var_dump($c->execute($req));
echo "</pre>";
Server response in SXML:
object(SimpleXMLElement)#2717 (2) {
["resp_result"]=>
object(SimpleXMLElement)#2486 (3) {
["resp_code"]=>
string(3) "200"
["resp_msg"]=>
string(13) "Call succeeds"
["result"]=>
object(SimpleXMLElement)#2500 (4) {
["current_page_no"]=>
string(1) "1"
["current_record_count"]=>
string(1) "2"
["products"]=>
object(SimpleXMLElement)#2493 (1) {
["product"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#2434 (29) {
["app_sale_price"]=>
string(4) "1.50"
["app_sale_price_currency"]=>
string(3) "USD"
["commission_rate"]=>
string(4) "9.0%"
["discount"]=>
string(3) "80%"
["first_level_category_id"]=>
string(2) "34"
["first_level_category_name"]=>
string(32) "Automobiles, Parts & Accessories"
["hot_product_commission_rate"]=>
string(4) "0.0%"
["lastest_volume"]=>
string(1) "0"
["original_price"]=>
string(4) "7.50"
["original_price_currency"]=>
string(3) "USD"
["product_detail_url"]=>
string(53) "https://www.aliexpress.com/item/1005002897604484.html"
["product_id"]=>
string(16) "1005002897604484"
["product_main_image_url"]=>
string(65) "https://ae04.alicdn.com/kf/H251d6cd1fb6b457f86d9418c8fb69bfc4.jpg"
["product_small_image_urls"]=>
object(SimpleXMLElement)#2431 (1) {
["string"]=>
array(6) {
[0]=>
string(65) "https://ae04.alicdn.com/kf/H251d6cd1fb6b457f86d9418c8fb69bfc4.jpg"
[1]=>
string(65) "https://ae04.alicdn.com/kf/Hef9247dcda18452b86cec742dc6e1512T.jpg"
[2]=>
string(65) "https://ae04.alicdn.com/kf/H0c39946d5ce345feb6f8fe2785157a2aw.jpg"
[3]=>
string(65) "https://ae04.alicdn.com/kf/H46444b25ac824ca48144ce8a41de8df1E.jpg"
[4]=>
string(65) "https://ae04.alicdn.com/kf/Hd5ec838b5f2544b3a21827f2751bcf48y.jpg"
[5]=>
string(65) "https://ae04.alicdn.com/kf/H550518786e1a472ebc1cf0b8cfdc522f2.jpg"
}
}
["product_title"]=>
string(163) "Car Parasol Front Windshield Side Window Cover Interior UV-protective Curtain шторки для автомобиля шторка для автомобилей "
["promotion_link"]=>
string(807) "https://s.click.aliexpress.com/s/4BScZUQRCtnCPCxSv0PKwEvDQD4u6TRQDsTl9yY3LPNpjcFJYJYgdvBwDDpTrktMG0Bk7vaKjL6XyPRVpHoWa7nQNlQFkqJPggCvZt8DKU9umyHh6eIX5opg0KuXEYNPi7ieG5LeqJDbqOacEd03kB7TjoPS5lw5oIH5JFWbhzN203U3K2CHxLHglZ3KrbYkGRGOE1cgm0v2oQRL2P5WzsJEV9UY7mMsJJsfwdoEo4YKzpQ4A6hFKY1Q4wYvOojPSfj2bFrEVwvkPSR5Y6FnaSrCZc6K5dZ2jfPZN2c5Uz6ken8DkMcl0at0TpyWMnasTOgxAit4gFga3NDjwESqiUlIktUrZigriucp0TyWz5DmYrGN654flY9yNmmuVez6QNmDok6kjJHM2iFZeBpJBYwSpaEMGvA21M0pjyJqLzq0lO7917WednH9wn4FJlFBHs5yGVX2PaCvU9EH41B3YaDNHDfKWP9aj0XcvBrV85e7h6Zukmu3erQ1h85q1gaClmOGLuF1rrw8w5b4j4NoikPBrUQlBXFQxH8B6bISevyTUl95U1uWA7Gt4uk4ySEEqlsHQLrcVwcF70ySnxuoDQ5dCf6LjaoOs8SOMJRm6I8SippRCihNz7PiLXmfmhyaTO6Bcff1hHQ4xIa4bwasbnh5IL3kF3MobRZBYCinXezrYyhCxlXrqw1GbFYwJ1dc9NGGSwU33s6x8XBpjUzib5y5uE1NVAwTBFCdwOewHMKpebf9e5El5yOT9IQBp2tp2O7zWr"
["relevant_market_commission_rate"]=>
string(4) "3.0%"
["sale_price"]=>
string(4) "1.50"
["sale_price_currency"]=>
string(3) "USD"
["second_level_category_id"]=>
string(9) "200003411"
["second_level_category_name"]=>
string(20) "Interior Accessories"
["shop_id"]=>
string(9) "912064829"
["shop_url"]=>
string(42) "https://www.aliexpress.com/store/912064829"
["target_app_sale_price"]=>
string(4) "1.50"
["target_app_sale_price_currency"]=>
string(3) "USD"
["target_original_price"]=>
string(4) "7.50"
["target_original_price_currency"]=>
string(3) "USD"
["target_sale_price"]=>
string(4) "1.50"
["target_sale_price_currency"]=>
string(3) "USD"
}
[1]=>
object(SimpleXMLElement)#2432 (29) {
["app_sale_price"]=>
string(4) "1.35"
["app_sale_price_currency"]=>
string(3) "USD"
["commission_rate"]=>
string(4) "9.0%"
["discount"]=>
string(3) "73%"
["first_level_category_id"]=>
string(2) "34"
["first_level_category_name"]=>
string(32) "Automobiles, Parts & Accessories"
["hot_product_commission_rate"]=>
string(4) "0.0%"
["lastest_volume"]=>
string(1) "0"
["original_price"]=>
string(4) "5.00"
["original_price_currency"]=>
string(3) "USD"
["product_detail_url"]=>
string(53) "https://www.aliexpress.com/item/1005003402966179.html"
["product_id"]=>
string(16) "1005003402966179"
["product_main_image_url"]=>
string(65) "https://ae04.alicdn.com/kf/Hd263fbbd1dad4d49a3a3277261c6c408L.jpg"
["product_small_image_urls"]=>
object(SimpleXMLElement)#2431 (1) {
["string"]=>
array(5) {
[0]=>
string(65) "https://ae04.alicdn.com/kf/Hd263fbbd1dad4d49a3a3277261c6c408L.jpg"
[1]=>
string(65) "https://ae04.alicdn.com/kf/H3595b1b670c04d8b95307ad54f30ee5ac.jpg"
[2]=>
string(65) "https://ae04.alicdn.com/kf/Hbc1076a0bbca4f91a60d8eb27f9392547.jpg"
[3]=>
string(65) "https://ae04.alicdn.com/kf/H999a513e61be49d2ad374fa87e4f34897.jpg"
[4]=>
string(65) "https://ae04.alicdn.com/kf/H7e29d629b6d04ec8870f166a71cf87212.jpg"
}
}
["product_title"]=>
string(124) "2022 New Car Interior Accessories Car Perfume Aromatherapy Cute Crown Teddy Bear Air Outlet Plaster Bear Ornament Decoration"
["promotion_link"]=>
string(807) "https://s.click.aliexpress.com/s/4BScZUQRCtnCPCxSv0PKwEvDQD4u6TRQDsTl9yY3LPNpjcFJYJYgdvBwDDpTrktMG0Bk7vaKjL6XyPRVpHoWa7nQNlQFkqJPggCvZt8DKU9umyHh6eIX5opg0KuXEYNPi7ieG5LeqJDbqOacEd03kB7TjoPS5lw5oIH5JFWbhzN203U3K2CHxLHglZ3KrbYkGRGOE1cgm0v2oQRL2P5WzsJEV9UY7mMsJJsfwdoEo4YKzpQ4A6hFKY1Q4wYvOojPSfj2bFrEVwvkPSR5Y6FnaSrCZc6K5dZ2jfPZN2c5Uz6ken8DkMcl0at0TpyYdHF0HQtA8jRRgCMGPA1XaVUh1IydbFgJOCvwetULs4d0J8ib9Xni5t3QrUNsxQ3lSARntkxnshpruYkDmzb3HJ3sf9GyH5rTL3OTC0dpG3XfbyCmQI7sE1rDkdWSBbIvIHJXWaawBxtuhmqr6WfjZDNeYY0JfdgUsh9F8OqLed1uePoqJHK8FdFG6GAnXwZkCbS84viXRSeHP4EjjjC4Z7gtBzNveIjurnHopaqkY4FNXnJzdGJwnudZyXpX7pV7jkaygdr7GnlfsroGM4P1e8GnFgcimWdqfV0vg71vTxlBJmVDSrtmndZVpTXu3dfIZbjuIyWZWwlCrKCxWbqsppQYItz8662L6l9uKNJLIoKipN0ZTyWkGA2XYBg9al3sPUsO39aTK7ZnxOr3SWOk8Zo6Ua3q3v6UemjvLqqruSU46TCFydPTWxg9wegSuYctUTY0MgdLen"
["relevant_market_commission_rate"]=>
string(4) "3.0%"
["sale_price"]=>
string(4) "1.35"
["sale_price_currency"]=>
string(3) "USD"
["second_level_category_id"]=>
string(9) "200003411"
["second_level_category_name"]=>
string(20) "Interior Accessories"
["shop_id"]=>
string(9) "912521256"
["shop_url"]=>
string(42) "https://www.aliexpress.com/store/912521256"
["target_app_sale_price"]=>
string(4) "1.35"
["target_app_sale_price_currency"]=>
string(3) "USD"
["target_original_price"]=>
string(4) "5.00"
["target_original_price_currency"]=>
string(3) "USD"
["target_sale_price"]=>
string(4) "1.35"
["target_sale_price_currency"]=>
string(3) "USD"
}
}
}
["total_record_count"]=>
string(6) "472235"
}
}
["request_id"]=>
string(12) "iirdj5wwp91x"
}
I need for example olny strings: Title["product_title"], Price["sale_price"] and TrackID["promotion_link"], how I can get it's? And show on web page only this data:
<h1>Title</h1>
<h2>Price</h2>
<a href>TrackID</a>
Thanks!
try this.
$content = "xml content";
$xml = new \SimpleXMLElement($content);
foreach($xml->resp_result->result->products->product as $product) {
echo "<h1>" . $product->product_title . "</h1>";
echo "<h2>" . $product->sale_price . "</h2>";
echo "<a href>" . $product->promotion_link . "</a>";
}
if not running or error, check if php-xml module as installed.
Im trying many days now to select data from this db
[1]: https://i.stack.imgur.com/QA34L.jpg
I want to print for example all comments
echo $comment['username']." | "; \ Alex | Alex
My php code so far:
[![$m= new MongoDB\Client ("mongodb://127.0.0.1/");
$db = $m->stores;
$collection = $db->storeinfo;][1]][1]
$storez = $collection->find(array("Products.pTHUMBNAIL" => $pThumb));
$o=1;
$afm=array();
foreach ($storez as $stor) {
$afm[$o] = $stor['AFM'];
$record = $collection->findOne(array(
"AFM" => $afm[$o],"Products.pTHUMBNAIL" => $pThumb));
foreach ($record['Products'] as $pro){
if($pThumb == $pro['pTHUMBNAIL']){
echo $temp = $pro['pID']." ";
foreach($pro as $pro1['pCOMMENTS']) {
foreach($pro1 as $com['Comment']) {
var_dump($com['Comment']);
/*
foreach($com as $comment) {
echo $comment['username'];
}
*/
}
}
}
}
$o += 1;
}
It seems that i just cannot find the correct foreach to loop through my Comment array
var_dump output:
099360111/1 object(MongoDB\BSON\ObjectId)#55 (1) { ["oid"]=> string(24) "6003403a695900000c002649" } string(11) "099360111/1" string(9) "Old Skool" string(2) "75" string(4) "Vans" string(25) "Leather and textile upper" string(2) "44" string(18) "Men/Shoes/Trainers" string(52) "http://127.0.0.1/pricedoc/assets/img/products/p1.jpg" string(1) "7" object(MongoDB\Model\BSONArray)#65 (1) { ["storage":"ArrayObject":private]=> array(1) { [0]=> object(MongoDB\Model\BSONDocument)#10 (1) { ["storage":"ArrayObject":private]=> array(1) { ["Comment"]=> object(MongoDB\Model\BSONDocument)#73 (1) { ["storage":"ArrayObject":private]=> array(4) { ["username"]=> string(4) "Alex" ["date"]=> object(MongoDB\BSON\UTCDateTime)#45 (1) { ["milliseconds"]=> string(13) "1611028053000" } ["text"]=> string(21) "1st comment from user" ["rating"]=> string(1) "4" } } } } } } 099360666/1 object(MongoDB\BSON\ObjectId)#44 (1) { ["oid"]=> string(24) "6006563a3f1c0000c80034a8" } string(11) "099360666/1" string(12) "old school 2" string(2) "50" string(4) "Vans" string(11) "black/white" string(8) "42,43,43" string(18) "Men/Shoes/Trainers" string(52) "http://127.0.0.1/pricedoc/assets/img/products/p1.jpg" string(1) "6" object(MongoDB\Model\BSONArray)#79 (1) { ["storage":"ArrayObject":private]=> array(2) { [0]=> object(MongoDB\Model\BSONDocument)#7 (1) { ["storage":"ArrayObject":private]=> array(1) { ["Comment"]=> object(MongoDB\Model\BSONDocument)#39 (1) { ["storage":"ArrayObject":private]=> array(4) { ["username"]=> string(4) "Alex" ["date"]=> object(MongoDB\BSON\UTCDateTime)#68 (1) { ["milliseconds"]=> string(13) "1611028089000" } ["text"]=> string(21) "1st comment from user" ["rating"]=> string(1) "4" } } } } [1]=> object(MongoDB\Model\BSONDocument)#78 (1) { ["storage":"ArrayObject":private]=> array(1) { ["Comment"]=> object(MongoDB\Model\BSONDocument)#77 (1) { ["storage":"ArrayObject":private]=> array(4) { ["username"]=> string(4) "Alex" ["date"]=> object(MongoDB\BSON\UTCDateTime)#76 (1) { ["milliseconds"]=> string(13) "1611030745000" } ["text"]=> string(8) "good!!!!" ["rating"]=> string(1) "5" } } } } } }
What about this?
After echo $temp = $pro['pID']." ";
foreach($pro['pCOMMENTS'] as $comments) {
foreach ($comments['Comment'] as $comment) {
echo $comment['text'];
}
}
You used foreach() bad: the index should be added to the first parameter, not in the 'as' part.
Also it helps if you use more clear variable names. That doesn't take too much, but makes it more readable and easy to debug.
After echo $temp = $pro['pID']." ";
foreach($pro['pCOMMENTS'] as $comments) {
foreach($comments as $comment) {
echo $comment['text'];
}
}
I need to print json response in php/html table, I am stuck for 4 days..
i have the json response as follows, it displays on the link http://localhost:8080/fb/?code=AQCtq-HglnDn5OZGCZAgnqiDHgL6fRHIC0054JJs6HgMmqw8h_qNDSqToe4ZxAM6kkGLDIzUaoruR0rfSlSenwRnWNv6Q6TH0Gbf6jbQ73m1uVEYnt_jrPiyawtKvj6bASITtMFC41Lly5SO25NOBRXP00RWN3uQoB3SxOe3ok3eypFZ26IRW1amNhDj3QdknvjpqsrpyhEUwK3NnHkRZmQqCKdvXywcZ-ENRxYAwN1rg4Gt0-fsdpnnKaQNx63MkXm6qEiSyIMPnZVHE7QPAJzIgdmUtK-aJD5lePpoIVJKT9P-Yy0R3ZIB2rHR5OTorx1WUOs5gHI7ANDEQnJN4mB4&state=32c7de5b745a4def2865de6684770d2d#=
array(3) {
["data"]=>
array(25) {
[0]=>
array(2) {
["id"]=>
string(15) "961716293930505"
["name"]=>
string(10) "Nena Gomez"
}
[1]=>
array(2) {
["id"]=>
string(15) "738589686317947"
["name"]=>
string(13) "Betuxx Chacon"
}
[2]=>
array(2) {
["id"]=>
string(17) "10154358290553845"
["name"]=>
string(24) "Gabriel Heredia Briseño"
}
[3]=>
array(2) {
["id"]=>
string(16) "1568587126490267"
["name"]=>
string(18) "Armando Von Thesse"
}
[4]=>
array(2) {
["id"]=>
string(17) "10211420006316586"
["name"]=>
string(11) "Any Obregon"
}
[5]=>
array(2) {
["id"]=>
string(16) "1464100830268739"
["name"]=>
string(35) "AarOnn LeOnne Raamiireez Raamiireez"
}
[6]=>
array(2) {
["id"]=>
string(16) "1210996895614354"
["name"]=>
string(23) "María José Hernández"
}
[7]=>
array(2) {
["id"]=>
string(17) "10205997740821868"
["name"]=>
string(14) "Mario Martinez"
}
[8]=>
array(2) {
["id"]=>
string(16) "1898457230384035"
["name"]=>
string(23) "Veronica Ramirez Cuevas"
}
[9]=>
array(2) {
["id"]=>
string(16) "1333307456741256"
["name"]=>
string(17) "Nicacio González"
}
[10]=>
array(2) {
["id"]=>
string(17) "10210081324343375"
["name"]=>
string(20) "Ariela Ampai Herrera"
}
[11]=>
array(2) {
["id"]=>
string(16) "1383385655027101"
["name"]=>
string(10) "Leyda Luna"
}
[12]=>
array(2) {
["id"]=>
string(17) "10154085294360936"
["name"]=>
string(17) "Ivan Azael Rivera"
}
[13]=>
array(2) {
["id"]=>
string(16) "1839478686312278"
["name"]=>
string(16) "Isamar Rodriguez"
}
[14]=>
array(2) {
["id"]=>
string(15) "954280078035568"
["name"]=>
string(32) "Seylin Mariana Brenes Peñaranda"
}
[15]=>
array(2) {
["id"]=>
string(16) "1220976504656199"
["name"]=>
string(17) "Yamili Ch Smendez"
}
[16]=>
array(2) {
["id"]=>
string(16) "1231937083552234"
["name"]=>
string(13) "Kennya Huerta"
}
[17]=>
array(2) {
["id"]=>
string(16) "1055827734543856"
["name"]=>
string(22) "Lizarazu Mario Esteban"
}
[18]=>
array(2) {
["id"]=>
string(15) "692883830880037"
["name"]=>
string(14) "Luian Suyos CA"
}
[19]=>
array(2) {
["id"]=>
string(16) "1223005904451888"
["name"]=>
string(12) "Rojas Andres"
}
[20]=>
array(2) {
["id"]=>
string(16) "1330174903721200"
["name"]=>
string(13) "Andrey Muñoz"
}
[21]=>
array(2) {
["id"]=>
string(17) "10210287624562868"
["name"]=>
string(27) "Carlos Manuel Veloz Sanchez"
}
[22]=>
array(2) {
["id"]=>
string(16) "1454728524567426"
["name"]=>
string(14) "Brandon Marín"
}
[23]=>
array(2) {
["id"]=>
string(16) "1809382102646429"
["name"]=>
string(27) "Dulce Maria Garcia Alvarado"
}
[24]=>
array(2) {
["id"]=>
string(15) "244610952637604"
["name"]=>
string(12) "Nafancy Soto"
}
}
["paging"]=>
array(2) {
["cursors"]=>
array(2) {
["before"]=>
string(20) "OTYxNzE2MjkzOTMwNTA1"
["after"]=>
string(20) "MjQ0NjEwOTUyNjM3NjA0"
}
["next"]=>
string(296) "https://graph.facebook.com/v2.8/778837615590033/likes?access_token=EAAW6655F9B8BADxO2m3VFKuNs7mEifqLGhDWEBxUtvL9jF8x8ZATLWUl0ZBR6jephQjNpWuuZCbgosbZCZAaNJLxeJ9seTxBQPneYGWMvf2I89ZAt2jOdV3rJu7iemXniCG6LiWDdUyjBl43ocEaRXPTN5qxzlPgcZD&pretty=1&summary=total_count&limit=25&after=MjQ0NjEwOTUyNjM3NjA0"
}
["summary"]=>
array(1) {
["total_count"]=>
int(28215)
}
}
likes count 28215
and my code is
<?php
session_start();
require_once __DIR__ .'/Facebook/autoload.php';
$fb = new \Facebook\Facebook([
'app_id' => '1612896019018783',
'app_secret' =>'483a369576ee496cce5780b0d5e23202' ,
'default_graph_version' => 'v2.8',
]);
$permissions = ['user_photos'];
$helper = $fb->getRedirectLoginHelper();
$accessToken=$helper->getAccessToken();
if(isset($accessToken)){
$url = "https://graph.facebook.com/v2.8/778837615590033/likes?&summary=total_count&access_token={$accessToken}";
//$url = "https://graph.facebook.com/v2.8/1205547979521647?fields=posts{likes,comments}&access_token={$accessToken}";
//$url = "https://graph.facebook.com/v2.8/1205547979521647?me?fields=id,name&access_token={$accessToken}";
$header=array("Content-type: application/json");
$ch=curl_init();
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows;U;
Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$st=curl_exec($ch);
$result=json_decode($st,TRUE);
echo "<pre>";
var_dump($result);
echo "</pre>";
$likes = $result['summary']['total_count'];
echo "likes count ". $likes;
//echo "<center>";
//echo "<img width='700' height='450' src= ><br><br>";
//echo "<img width='90' height='90' src=http://i.imgur.com/wVAJS8T.png";
//echo "</center>";
}
else
{
$loginUrl = $helper->getLoginUrl('http://localhost:8080/fb/',$permissions);
echo 'Login with FB';
}
?>
I need to display the results in results.php in table format
$data = $result['data'];
echo '<table>';
echo '<tr><td>id</td><td>name</td></tr>';
foreach ($data as $item) {
echo '<tr>';
echo '<td>' . $item['id'] . '</td>';
echo '<td>' . $item['name'] . '</td>';
echo '</tr>';
addMysql($item['id'], $item['name']);
}
echo '</table>';
function addMysql($id, $name) {
$sql = "INSERT INTO table_name (`id`, `name`) VALUE ($id, $name);";
// instance mysql driver
mysql_query($sql);
}
Your $result is in array format.So just use the table tag as below.
$result=json_decode($st,TRUE);
echo "<table>";
foreach ($result as $res) {
echo "<tr>";
echo "<td>".$res['data']['id']."</td">;
echo "<td>".$res['data']['name']."</td>";
echo "</tr">;
}
echo "</table>"
i have the following array:
[2]=>
object(stdClass)#9 (4) {
["ID"]=>
string(32) "43c845f895a56fbe8aea9435ef8fa806"
["Type"]=>
string(8) "Campaign"
["Name"]=>
string(28) "An unmissable invitation for"
["Actions"]=>
array(5) {
[0]=>
object(stdClass)#10 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-05-07 17:00:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(0) ""
}
[1]=>
object(stdClass)#11 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-05-07 09:01:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(0) ""
}
[2]=>
object(stdClass)#12 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-04-30 22:29:00"
["IPAddress"]=>
string(14) "94.171.192.216"
["Detail"]=>
string(0) ""
}
[3]=>
object(stdClass)#13 (4) {
["Event"]=>
string(5) "Click"
["Date"]=>
string(19) "2013-04-30 17:43:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(60) "http://www.rbh.co.uk/rbhevent/?name=[fullname]&email=[email]"
}
[4]=>
object(stdClass)#14 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-04-30 17:43:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(0) ""
}
}
}
i am trying to count the events that are the same. So for example ["Event"] = Open =4 / ["Event"] = Click =1.
I am trying to achieve this via counting a foreach loop:
$i=0;
foreach($entry->Actions as $actions ) {
echo $i++;
}
Im not quite sure how to approach this? Can someone suggest a best practice?
$counts = array();
foreach($entry->Actions as $actions) {
if(!isset($counts[$actions->Event])) {
$counts[$actions->Event] = 0;
}
++$counts[$actions->Event];
}
print_r($counts);
<?php
$amounts = array(); // Events as key
foreach($entry->Actions as $actions)
{
if (isset($amounts[$actions["Event"]])) $amounts[$actions["Event"]]++;
else $amounts[$actions["Event"]] = 1;
}
print_r($amounts);
echo "<br>".$amounts["Open"];
?>