Note that there are some explanatory texts on larger screens.

plurals
  1. POodd behavior with Zend2/doctrine pagination when displaying the DB records in my view file
    primarykey
    data
    text
    <p>I am using the doctrine provided DoctrinePaginator (<a href="https://github.com/doctrine/DoctrineORMModule/blob/master/src/DoctrineORMModule/Paginator/Adapter/DoctrinePaginator.php" rel="nofollow">https://github.com/doctrine/DoctrineORMModule/blob/master/src/DoctrineORMModule/Paginator/Adapter/DoctrinePaginator.php</a>)</p> <p>But I'm encountering very very odd behavior.</p> <p>This is a screenshot (<a href="http://i.stack.imgur.com/ePL1F.jpg" rel="nofollow">http://i.stack.imgur.com/ePL1F.jpg</a>) of my SQL ran using SQL Developer (running oracle 11g here). This is basically what doctrine is running. As you can see at record 100 is a person with the lastname "Allen". The odd behavior happens when I try to display the records in my view file.</p> <p>This 2nd screenshot (<a href="http://i.imgur.com/3TxgeI3.jpg" rel="nofollow">http://i.imgur.com/3TxgeI3.jpg</a>) was made with $recordsPerPage set to 100 (see controller code below). The top of the image would tell you the SQL used ($queryBuilder->getDql()). As you can see from the image, the last person in the page is a person with the lastname "Azamov". According to the SQL I ran in SQL developer, the person in record 100 should have been a person with the lastname "Allen.</p> <p>You can also see the number 100 below "Azamov". This was calculated by initializing a variable called $tempCounter in my view page and then incrementing it using ++$tempCounter. (view code at the end)</p> <p>The 290 number you see near the top of the image is from $adapter->count() (also found in the controller code below).</p> <p>This 3rd screenshot (<a href="http://i.imgur.com/3qhVixW.jpg" rel="nofollow">http://i.imgur.com/3qhVixW.jpg</a>) was made with $recordPerPage set to 200. Again, "Azamov" was the last person.</p> <p>It seems to me that somehow, the records displayed are not following whatever order I set in my SQL.</p> <p>Any ideas what could be wrong? Thanks</p> <hr> <p><strong>this is my controller code</strong></p> <pre><code>public function searchAction() { $recordsPerPage = 100; if ($this-&gt;request-&gt;isGet()) { $form = new DirectorySearchForm(); $directory = new DirectoryModel(); $form-&gt;setInputFilter($directory-&gt;getInputFilter()); $form-&gt;setData($this-&gt;request-&gt;getQuery()); if ($form-&gt;isValid()) { $directoryDao = new DirectoryDao(); $directory-&gt;populate($form-&gt;getData()); $adapter = new DoctrineAdapter(new ORMPaginator($directoryDao-&gt;searchStaffDirectory($this-&gt;getEntityManager()-&gt;createQueryBuilder(), $directory))); $paginator = new Paginator($adapter); $paginator-&gt;setItemCountPerPage($recordsPerPage); $page = (int)$this-&gt;params()-&gt;fromQuery("page"); $paginator-&gt;setCurrentPageNumber($page); //var_dump(); return array( "staffList" =&gt; $paginator, "recordCount" =&gt; $adapter-&gt;count(), "recordsPerPage" =&gt; $recordsPerPage, ); } } return $this-&gt;viewModel; } </code></pre> <p><strong>my view code</strong></p> <pre><code>&lt;?php // Declare temporary variables here $oddEven = array('odd', 'even'); $tempCounter = 0; ?&gt; Found &lt;?php echo $recordCount; ?&gt; records&lt;br /&gt; &lt;table&gt; &lt;tr&gt; &lt;td colspan="4"&gt;&lt;a style="text-decoration: none" title="Many different prefixes apply to campus extensions. Click on name or phone number for contact details."&gt;&lt;h2&gt;Click on name or phone number for contact details&lt;/h2&gt;&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th scope="col" class="searchResults highlightOrgStructure"&gt;name&lt;/th&gt; &lt;th scope="col" class="searchResults highlightOrgStructure"&gt;Telephone&lt;/th&gt; &lt;th scope="col" class="searchResults highlightOrgStructure"&gt;Position&lt;/th&gt; &lt;th scope="col" class="searchResults highlightOrgStructure"&gt;Department&lt;/th&gt; &lt;/tr&gt; &lt;script type="text/javascript"&gt; $(function () { $(document).tooltip({ content: function () { return $(this).prop('title'); } }); }); &lt;/script&gt; &lt;?php foreach($staffList as $staff) { ?&gt; &lt;?php ++$tempCounter; ?&gt; &lt;tr class="&lt;?php echo $oddEven[$tempCounter % 2]; ?&gt;"&gt; &lt;td class="searchResults"&gt;&lt;?php echo $staff-&gt;surname; if (strlen($staff-&gt;firstname) &gt; 0) { echo ", ". $staff-&gt;firstname . " " . $staff-&gt;title; } ?&gt;&lt;/td&gt; &lt;td class="searchResults"&gt;&lt;?php echo $staff-&gt;telephoneNumber; ?&gt;&lt;/td&gt; &lt;td class="searchResults"&gt;&lt;?php echo $staff-&gt;role; ?&gt;&lt;/td&gt; &lt;td class="searchResults"&gt;&lt;?php echo $staff-&gt;department; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;?php echo $tempCounter."&lt;hr&gt;"; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload