0

I have this text ($results):

{"data":{"summary":{"records":67,"page":1,"total":67,"hasMore":0},"reservations":[{"id":1111111,"property":"villadianna","from":"2016-07-18","to":"2016-07-25"},"pricing":{"price":1164.2400,"currency":"EUR","retail":1323},"clientInfo":{"firstName":"pera","lastName":"peric","email":"[email protected]"},"status":1,"offline":0},{"id":222222,"property":"villadianna", etc. ... ...

Now I need to get reserations array and make foreach loop so I try:

...
$result = curl_exec($ch);
curl_close($ch);

$json = json_decode($result);
foreach ($json->reservations as $element) {
  print_r($element);
}

but I get errors: enter image description here

How to create html table with foreach loop only for reservations ?

7
  • 1
    Do a print_r($json); and look at the object you are dealing with. $json->data->reservations Commented Jul 13, 2016 at 16:09
  • var_dump() is better, since it'll output booleans properly. Commented Jul 13, 2016 at 16:12
  • @MarcB Personally hate the output from var_dump() only use it if I really have to and print_r() does not show enough detail which is rare in my experince but you are probably right Commented Jul 13, 2016 at 16:14
  • ok I make print_r($json); and I get screen with json as a text Commented Jul 13, 2016 at 16:18
  • So that is what your $json object looks like read it and understand its structure. If you read the lables you will see stdClass (means an object) or Array (means an array) Commented Jul 13, 2016 at 16:20

1 Answer 1

1
...
$result = curl_exec($ch);
curl_close($ch);

$json = json_decode($result);
foreach ($json->data->reservations as $element) {
  print_r($element);
}
Sign up to request clarification or add additional context in comments.

2 Comments

but where is the table ? how to create html table with data ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.