title: PHP odbc_exec not returning all rows
body: <p>This simple query</p>
  <pre><code>SELECT 
      DBA.Goods.ID,  /* PK in the Goods table */
      DBA.Goods.Name,
      DBA.GoodsGroup.Name as GdGrp,
      DBA.InvoiceItem.Qty,
      DBA.InvoiceItem.ID,   /* PK in the InvoiceItem table */
      DBA.InvoiceItem.PrintName,
      DBA.InvoiceItem.Price,
      DBA.InvoiceItem.InvoiceID, /* PK in the Invoice table, a parent table of a sort */
      DBA.InvoiceItem.InvoiceItemOrder,
      DBA.InvoiceItem.ProcPrice,
  FROM (
      DBA.Goods INNER JOIN DBA.InvoiceItem
          ON DBA.Goods.GoodsSk = DBA.InvoiceItem.GoodsSK
  )
  INNER JOIN DBA.GoodsGroup
      ON DBA.Goods.GroupID = DBA.GoodsGroup.ID
  WHERE DBA.InvoiceItem.InvoiceID = $invoiceID /* ID of a specific invoice, used here to get to its contents, i.e. specific items within that invoice */
  </code></pre>
  <p>when run in DBExplorer (a DB tool for executing raw SQL queries), returns 5 rows (contents of an invoice). Everything is setup in such a way that an invoice may contain multiple goods of the same ID (but with different prices and procurement prices, printing names - e.g. bucket-white, bucket-blue, bucket-red, etc). Each of the items gets a unique ID within the <code>Items</code> table. The aforementioned 5 rows are the expected result (i.e. the goods in the list are the actual goods sold).</p>
  <p>However, when the query is sent to the database via:</p>
  <pre><code>$result = odbc_exec($conn,$query);
  </code></pre>
  <p><code>odbc_num_rows($results)</code> is not 5, as expected and seen in DBExplorer, but 3 - the (percieved) duplicates are not returned (of all the buckets in the previous example, only one is returned).</p>
  <p>Furthermore, while looping through the results with</p>
  <pre><code>while($rowItems = odbc_fetch_object($result) {
      ...
  }
  </code></pre>
  <p>there are only 3 iterations, instead of the expected 5.</p>
  <p>Thinking that the column order might be causing problems (silly, I know), I moved the <code>DBA.InvoiceItem.ID</code> to the top, making it the first column in the result set. However, that did nothing.</p>
  <p>Why is this happening, and how can I make it return the full result set?</p>
  <p><strong>Note</strong></p>
  <p>I am aware that there are similar questions on SO:</p>
  <p><a href="https://stackoverflow.com/questions/34030330/php-odbc-exec-not-returning-all-results">php odbc_exec not returning all results</a></p>
  <p><a href="https://stackoverflow.com/questions/7367414/why-doesnt-this-code-return-all-rows">why doesn't this code return all rows?</a></p>
  <p><a href="https://stackoverflow.com/questions/27303060/not-getting-all-rows-from-a-query-with-odbc-exec-in-php">Not getting all rows from a query with odbc_exec in php</a></p>
  <p>but none of them actually address the issue presented here - how to get ALL of the rows as seen in the DB tool, instead of a reduced result set.</p>