title: Javascript: Extract correct json from php script using id
body: <p>The issue i am having is i am unable to figure out the correct code through which to extract the information i am looking for</p>
  
  <p>Here firstly is the exhibitions.php</p>
  
  <pre><code>&lt;?php
      $exhibitionsarray = array(
              array("exhibition_id" =&gt; "1", "exhibition_title" =&gt; "New York, New York", "exhibition_subject" =&gt; "New York", "ticket_price" =&gt; "10",
                  "exhibits" =&gt; array(
                      array("exhibit_id" =&gt; "3", "exhibit_title" =&gt; "Brooklyn Bridge from City Hall Park", "exhibit_description" =&gt; "New York, June 2005", "exhibit_image" =&gt; "brooklynbridge.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "6", "exhibit_title" =&gt; "Central Park, New York", "exhibit_description" =&gt; "New York, June 2005", "exhibit_image" =&gt; "centralpark.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "7", "exhibit_title" =&gt; "Chrysler Building at night, New York", "exhibit_description" =&gt; "New York, July 2001", "exhibit_image" =&gt; "chrysler_building.jpg", "photographer" =&gt; "MLG")
                  ),
                  "locations" =&gt; array(
                      array("location_id" =&gt; "1", "location_name" =&gt; "Kelvingrove Art Gallery and Museum", "location_postcode" =&gt; "G3 8AG"),
                      array("location_id" =&gt; "3", "location_name" =&gt; "Walker Art Gallery", "location_postcode" =&gt; "L3 8EL"),
                      array("location_id" =&gt; "5", "location_name" =&gt; "Tate Modern", "location_postcode" =&gt; "SE1 9TG")
                  )
              ),
              array("exhibition_id" =&gt; "2", "exhibition_title" =&gt; "Spanish Cities", "exhibition_subject" =&gt; "Spain", "ticket_price" =&gt; "15",
                  "exhibits" =&gt; array(
                      array("exhibit_id" =&gt; "9", "exhibit_title" =&gt; "Eiffel Bridge, Girona", "exhibit_description" =&gt; "Girona, March 2008", "exhibit_image" =&gt; "eiffel_bridge.jpg", "photographer" =&gt; "LPK"),
                      array("exhibit_id" =&gt; "13", "exhibit_title" =&gt; "Plaza Mayor, Madrid", "exhibit_description" =&gt; "Madrid, June 2010", "exhibit_image" =&gt; "plazamayor.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "14", "exhibit_title" =&gt; "Puppy (Day)", "exhibit_description" =&gt; "Bilbao, September 2006 - Puppy in daylight", "exhibit_image" =&gt; "puppy_day.jpg", "photographer" =&gt; "LPK"),
                      array("exhibit_id" =&gt; "15", "exhibit_title" =&gt; "Puppy (Night)", "exhibit_description" =&gt; "Bilbao, March 2011 - Puppy at night", "exhibit_image" =&gt; "puppy_night.jpg", "photographer" =&gt; "LPK")                                                                      
                  ),
                  "locations" =&gt; array(
                      array("location_id" =&gt; "2", "location_name" =&gt; "Scottish National Gallery", "location_postcode" =&gt; "EH2 2EL")
                  )                                               
              ),
              array("exhibition_id" =&gt; "3", "exhibition_title" =&gt; "A Glasgow Viewpoint", "exhibition_subject" =&gt; "Glasgow", "ticket_price" =&gt; "5",
                  "exhibits" =&gt; array(
                      array("exhibit_id" =&gt; "2", "exhibit_title" =&gt; "Bothwell Castle", "exhibit_description" =&gt; "Bothwell, April 2011", "exhibit_image" =&gt; "bothwell_castle.jpg", "photographer" =&gt; "LPK"),
                      array("exhibit_id" =&gt; "10", "exhibit_title" =&gt; "Hampden Park", "exhibit_description" =&gt; "Glasgow, June 2007 - SQA Event", "exhibit_image" =&gt; "hampden.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "11", "exhibit_title" =&gt; "Hogganfield Loch, Glasgow, Winter", "exhibit_description" =&gt; "Glasgow, January 2010", "exhibit_image" =&gt; "hogganfield_loch.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "16", "exhibit_title" =&gt; "Ramblas", "exhibit_description" =&gt; "Barcelona, July 1999 - Ramblas (Two Old Friends from Glasgow)", "exhibit_image" =&gt; "ramblas.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "17", "exhibit_title" =&gt; "River Clyde at Bothwell", "exhibit_description" =&gt; "Bothwell, April 2011 - River Clyde from Bothwell", "exhibit_image" =&gt; "river_clyde.jpg", "photographer" =&gt; "LPK"),
                      array("exhibit_id" =&gt; "18", "exhibit_title" =&gt; "River Kelvin", "exhibit_description" =&gt; "Glasgow, July 2011", "exhibit_image" =&gt; "river_kelvin.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "21", "exhibit_title" =&gt; "University Avenue", "exhibit_description" =&gt; "Glasgow, July 2011", "exhibit_image" =&gt; "university_avenue.jpg", "photographer" =&gt; "LPK")                                                                     
                  ),
                  "locations" =&gt; array(
                      array("location_id" =&gt; "1", "location_name" =&gt; "Kelvingrove Art Gallery and Museum", "location_postcode" =&gt; "G3 8AG"),
                      array("location_id" =&gt; "2", "location_name" =&gt; "Scottish National Gallery", "location_postcode" =&gt; "EH2 2EL"),
                      array("location_id" =&gt; "3", "location_name" =&gt; "Walker Art Gallery", "location_postcode" =&gt; "L3 8EL"),
                      array("location_id" =&gt; "4", "location_name" =&gt; "The Lowry", "location_postcode" =&gt; "M50 3AZ"),
                      array("location_id" =&gt; "5", "location_name" =&gt; "Tate Modern", "location_postcode" =&gt; "SE1 9TG")
                  )                                                   
              ),
              array("exhibition_id" =&gt; "4", "exhibition_title" =&gt; "Some Churches", "exhibition_subject" =&gt; "Religious Architecture", "ticket_price" =&gt; "5",
                  "exhibits" =&gt; array(
                      array("exhibit_id" =&gt; "1", "exhibit_title" =&gt; "Big Ben", "exhibit_description" =&gt; "London, September 2011", "exhibit_image" =&gt; "big_ben.jpg", "photographer" =&gt; "LPK"),
                      array("exhibit_id" =&gt; "12", "exhibit_title" =&gt; "Louvre, Paris", "exhibit_description" =&gt; "Paris, June 1998", "exhibit_image" =&gt; "louvre.jpg", "photographer" =&gt; "LPK"),
                      array("exhibit_id" =&gt; "19", "exhibit_title" =&gt; "Sagrada Familia - Honeymoon", "exhibit_description" =&gt; "Barcelona, June 1997 - Honeymoon", "exhibit_image" =&gt; "sagrada.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "20", "exhibit_title" =&gt; "Mormon Temple", "exhibit_description" =&gt; "Salt Lake City, July 2005", "exhibit_image" =&gt; "salt_lake.jpg", "photographer" =&gt; "MLG")                                                                      
                  ),
                  "locations" =&gt; array(
                      array("location_id" =&gt; "1", "location_name" =&gt; "Kelvingrove Art Gallery and Museum", "location_postcode" =&gt; "G3 8AG"),
                      array("location_id" =&gt; "2", "location_name" =&gt; "Scottish National Gallery", "location_postcode" =&gt; "EH2 2EL")
                  )                                                   
              ),
              array("exhibition_id" =&gt; "5", "exhibition_title" =&gt; "Barcelona Highlights", "exhibition_subject" =&gt; "Barcelona", "ticket_price" =&gt; "15",
                  "exhibits" =&gt; array(
                      array("exhibit_id" =&gt; "4", "exhibit_title" =&gt; "Martin at Camp Nou, Honeymoon", "exhibit_description" =&gt; "Barcelona, June 1997 - Honeymoon", "exhibit_image" =&gt; "campnou.jpg", "photographer" =&gt; "LPK"),
                      array("exhibit_id" =&gt; "5", "exhibit_title" =&gt; "Placa de Catalunya, Barcelona - Honeymoon", "exhibit_description" =&gt; "Barcelona, June 1997 - Honeymoon", "exhibit_image" =&gt; "catalunya.jpg", "photographer" =&gt; "MLG")
                  ),
                  "locations" =&gt; array(
                      array("location_id" =&gt; "3", "location_name" =&gt; "Walker Art Gallery", "location_postcode" =&gt; "L3 8EL"),
                      array("location_id" =&gt; "4", "location_name" =&gt; "The Lowry", "location_postcode" =&gt; "M50 3AZ"),
                      array("location_id" =&gt; "5", "location_name" =&gt; "Tate Modern", "location_postcode" =&gt; "SE1 9TG")
                  )                                                   
              ),
              array("exhibition_id" =&gt; "6", "exhibition_title" =&gt; "Martin’s Pictures", "exhibition_subject" =&gt; "Martin", "ticket_price" =&gt; "5",
                  "exhibits" =&gt; array(
                      array("exhibit_id" =&gt; "8", "exhibit_title" =&gt; "David Crosby at David Gilmour gig", "exhibit_description" =&gt; "Glasgow, May 2006", "exhibit_image" =&gt; "davidcrosby.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "22", "exhibit_title" =&gt; "Wolves", "exhibit_description" =&gt; "Yellowstone Park, October 2004", "exhibit_image" =&gt; "wolves.jpg", "photographer" =&gt; "MLG")
                  ),
                  "locations" =&gt; array(
                      array("location_id" =&gt; "1", "location_name" =&gt; "Kelvingrove Art Gallery and Museum", "location_postcode" =&gt; "G3 8AG"),
                      array("location_id" =&gt; "3", "location_name" =&gt; "Walker Art Gallery", "location_postcode" =&gt; "L3 8EL"),
                      array("location_id" =&gt; "4", "location_name" =&gt; "The Lowry", "location_postcode" =&gt; "M50 3AZ"),
                      array("location_id" =&gt; "5", "location_name" =&gt; "Tate Modern", "location_postcode" =&gt; "SE1 9TG")
                  )
              )               
      );
      echo json_encode($exhibitionsarray);
  ?&gt;
  </code></pre>
  
  <p>The information i wish depends on the specific exhibition id... and only use exhibits not location so for example when the id = 1  i wish this information...</p>
  
  <pre><code>array("exhibition_id" =&gt; "1", "exhibition_title" =&gt; "New York, New York", "exhibition_subject" =&gt; "New York", "ticket_price" =&gt; "10",
                  "exhibits" =&gt; array(
                      array("exhibit_id" =&gt; "3", "exhibit_title" =&gt; "Brooklyn Bridge from City Hall Park", "exhibit_description" =&gt; "New York, June 2005", "exhibit_image" =&gt; "brooklynbridge.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "6", "exhibit_title" =&gt; "Central Park, New York", "exhibit_description" =&gt; "New York, June 2005", "exhibit_image" =&gt; "centralpark.jpg", "photographer" =&gt; "MLG"),
                      array("exhibit_id" =&gt; "7", "exhibit_title" =&gt; "Chrysler Building at night, New York", "exhibit_description" =&gt; "New York, July 2001", "exhibit_image" =&gt; "chrysler_building.jpg", "photographer" =&gt; "MLG")
                  ),
  </code></pre>
  
  <p>Now here is the code i currently have to get all exhibit info</p>
  
  <pre><code>function getExibitions()
  {
      console.log(json);
  myExhibitionsView = document.getElementById('exhibitioncontent');
  images = document.createElement('ul');
  
  for (var i = 0; i &lt; json.length; i++) {
      for (var j = 0; j &lt; json[i].exhibits.length; j++) {
          listCheck = document.createElement('p');
          listCheck.id = 'image';
          listCheck.innerHTML = "&lt;img src = " + "./images/" + json[i].exhibits[j].exhibit_image + " Photo Cover' height='200' width='200'&gt;";
          console.log(listCheck);
          myExhibitionsView.appendChild(images);
          images.appendChild(listCheck);
          console.log(listCheck);
      }
  }
  
  }
  </code></pre>
  
  <p>This code allows me to extract the json and then use the image urls... this is what i wish to do here as well but only if its of the specific id. Thank you very much for the assistance </p>