title: Google APIs Library for PHP Loop
body: <p>I am using the <a href="https://github.com/google/google-api-php-client" rel="nofollow noreferrer">Google APIs Client Library for PHP</a> which I currently have working with the Codeigniter framework. I am able to display a book title and image when I manually enter an ISBN number in the API code.</p>
  
  <p>Each result in the table should display the corresponding title and image from Google Books.</p>
  
  <p>Any help would be appreciated with this. Also, if my code could be improved I'd love to hear, I'm still learning :)</p>
  
  <p>My current working code is as follows;</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>class Items extends CI_Controller {
  
      public function index() {
          $data['items'] = $this-&gt;items_model-&gt;itemList(); 
  // var_dump($data['items']) returns the following (http://pastebin.com/4XVS4Whb)
  
          $client = new Google_Client();
          $client-&gt;setApplicationName("Client_Library_Examples");
          $client-&gt;setDeveloperKey("MyKeyHere");
          $service = new Google_Service_Books($client);
          $isbn = '0-7515-3831-0'; // &lt;- I need to replace this with my DB array
          $results = $service-&gt;volumes-&gt;listVolumes($isbn);
  
          foreach ($results as $item) {
  // var_dump($results) returns the following (http://pastebin.com/by50uLNq)
  // var_dump($item) returns the following (http://pastebin.com/b4vdt38P)
  
              $bookTitle = $item['volumeInfo']['title'];
              $bookImage = $item['volumeInfo']['imageLinks']['smallThumbnail'];
              $data['bookTitle'] = $bookTitle;
              $data['bookImage'] = $bookImage;
          }
          $this-&gt;load-&gt;view('item_view', $data);
      }
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>class Items_model extends CI_Model {
      public function itemList() {
          $query = $this-&gt;db-&gt;get('item', 10);
          return $query-&gt;result_array();
      }   
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;table&gt;
          &lt;tr&gt;
             &lt;td&gt;&lt;strong&gt;Title&lt;/strong&gt;&lt;/td&gt;
             &lt;td&gt;&lt;strong&gt;Image&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;?php echo $bookTitle ?&gt;&lt;/td&gt;         
              &lt;td&gt;&lt;?php echo echo '&lt;img src="'.$bookImage.'"&gt;';?&gt;&lt;/td&gt;    
          &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>