title: Something wrong with API or in the Loop?
body: <p>So I have this function that fetches API response.</p>
  
  <p>Here's what the API return response looks like;</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Response type="1"&gt;
  &lt;ack&gt;
      &lt;ackstatus&gt;OK&lt;/ackstatus&gt;
      &lt;ackreason&gt;&lt;/ackreason&gt;
  &lt;/ack&gt;
  &lt;dataversion&gt;1&lt;/dataversion&gt;
  &lt;hitcount&gt;13391&lt;/hitcount&gt;
  &lt;shops&gt;
      &lt;spad&gt;
                  &lt;/spad&gt;
      &lt;basead&gt;
          &lt;shop&gt;
              &lt;id&gt;KN0100060500216636&lt;/id&gt;
              &lt;priority&gt;1&lt;/priority&gt;
              &lt;entryname&gt;旭川職業能力開発促進センター&lt;/entryname&gt;
              &lt;telno&gt;0166-48-2412&lt;/telno&gt;
              &lt;zipcode&gt;079-8418&lt;/zipcode&gt;
              &lt;address&gt;北海道旭川市永山８条２０丁目３−１&lt;/address&gt;
              &lt;latitude&gt;157707796&lt;/latitude&gt;
              &lt;longitude&gt;512803967&lt;/longitude&gt;
              &lt;imageurl&gt;&lt;/imageurl&gt;
              &lt;promoword&gt;&lt;/promoword&gt;
              &lt;coupon&gt;0&lt;/coupon&gt;
              &lt;group&gt;0&lt;/group&gt;
              &lt;searchnum&gt;7214223&lt;/searchnum&gt;
          &lt;/shop&gt;
          &lt;shop&gt;
              &lt;id&gt;KN0100060500202256&lt;/id&gt;
              &lt;priority&gt;1&lt;/priority&gt;
              &lt;entryname&gt;旭川市立／嵐山小中学校&lt;/entryname&gt;
              &lt;telno&gt;0166-61-1199&lt;/telno&gt;
              &lt;zipcode&gt;070-8051&lt;/zipcode&gt;
              &lt;address&gt;北海道旭川市江丹別町嵐山１４３&lt;/address&gt;
              &lt;latitude&gt;157704475&lt;/latitude&gt;
              &lt;longitude&gt;512195888&lt;/longitude&gt;
              &lt;imageurl&gt;&lt;/imageurl&gt;
              &lt;promoword&gt;&lt;/promoword&gt;
              &lt;coupon&gt;0&lt;/coupon&gt;
              &lt;group&gt;0&lt;/group&gt;
              &lt;searchnum&gt;7214223&lt;/searchnum&gt;
          &lt;/shop&gt;
      &lt;/basead&gt;
  &lt;/shops&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>So in my function I have to fetch some details, example; id, entryname, so that I could use them as parameters to get a different API:</p>
  
  <p>Here's the function;
  (I put logs so if I run the script it shows what the results have got.)</p>
  
  <pre><code>public function getcompList($prefectureId,$industryId,$offset)
  {
      $itpCompanies = $this-&gt;itpApi-&gt;getCompanies($prefectureId,$industryId,$offset);
      $hascompany = $this-&gt;itpApi-&gt;getReturnArray();
  
      log_message('debug','Company list fetched, returning...');
  
      return $hascompany;
  }
  
  public function getcompanyList($hascompany,$prefectureId,$offset,$industryId)
  {
      foreach ( $hascompany['shops']['basead']['shop'] as $company ) {
          $companyId = $company['id'];
          $entryName = $company['entryname'];
          $priority = $company['priority'];
          $searchNum = $company['searchnum'];
  
          log_message('debug', 'Comp_List API: company_id = ' . print_r($companyId, true));
          log_message('debug', 'Comp_List API: company_name = ' . print_r($entryName, true));
          log_message('debug', 'Comp_List API: company_prio = ' . print_r($priority, true));
          log_message('debug', 'Comp_List API: company_searchno = ' . print_r($searchNum, true));
  
          log_message('debug', 'Company_List-&gt;Company_Detail:: Getting Company Detail...');
          $this-&gt;compModel-&gt;getDetail($prefectureId,$offset,$industryId,$companyId,$entryName,$priority,$searchNum);
      }
  
  }
  </code></pre>
  
  <p>So for example in the above API response, the logs will show;</p>
  
  <pre><code>Company list fetched, returning...
  Comp_List API: company_id = KN0100060500216636
  Comp_List API: company_name = 旭川職業能力開発促進センター
  Comp_List API: company_prio = 1
  Comp_List API: company_searchno = 7214223
  Company_List-&gt;Company_Detail:: Getting Company Detail...
  Company Detail Inserted!
  Comp_List API: company_id = KN0100060500202256
  Comp_List API: company_name = 旭川市立／嵐山小中学校
  Comp_List API: company_prio = 1
  Comp_List API: company_searchno = 7214223
  Company_List-&gt;Company_Detail:: Getting Company Detail...
  Company Detail Inserted!
  </code></pre>
  
  <p>The problem is when API response returns only 1 <code>&lt;shop&gt;</code>. It gives me this;</p>
  
  <pre><code>Comp_List API: company_id = K
  Comp_List API: company_name = K
  Comp_List API: company_prio = K
  Comp_List API: company_searchno = K
  Company_List-&gt;Company_Detail:: Getting Company Detail...
  </code></pre>
  
  <p>and because this function is also inside a loop that checks and gets the API, The result would then give me error; a duplicate query, etc.</p>
  
  <p>could it be a problem in the API? or the <code>foreach</code> loop in the <code>getcompanyList</code> function?</p>