How can I fix the pages pager returns? I have a number of "product nodes" that I'd like to return and display in a paged table.

The original query is generated as follows:

    $productNodeQuery = db_select('node', 'n')
    -&gt;fields('n', array('nid'))
    -&gt;condition('type', 'product', '=')
    -&gt;extend('TableSort')
    -&gt;extend('PagerDefault')
    -&gt;limit($page_limit);

    $productNodes = $productNodeQuery-&gt;execute();


This returns all the products I want, however the pages are all messed up. Some pages have 3 items, some pages have 10, others have the full $page_limit (50) items per page.

I have a loop 

foreach($productNodes as $productNode) {
....
}


to iterate over the results and add each product to the $rows[] array with this:

 $rows[] = array(
            'data' =&gt; array(
            'autoupdate' =&gt; $part['autoupdate'] == "1" ? 'ENABLED' : 'DISABLED',       // Display Checkbox?
            'part_number' =&gt; $part['part_number'],
            'title' =&gt; l($this_node-&gt;title, url($base_url . '/node/' . $this_node-&gt;nid)),
            'category' =&gt; l($this_category_name, url($base_url . '/catalog/' . str_replace(' ', '-', $this_category_name ))) . "&lt;br /&gt;(Markup: " . $this_markup_percent['suggested_markup']*100 . "%)",
            'supplier_price' =&gt; $supplier_prices_string != "" ? $supplier_prices_string : "N/A",
            'suggested_price' =&gt; isset($suggested_prices_string) ? $suggested_prices_string : "N/A",
            'sell_price' =&gt; '$' . number_format($this_node-&gt;sell_price, 2),
            'competitors_price' =&gt; isset($competitor_prices_string) ? $competitor_prices_string : "N/A",
           'edit_node' =&gt; l('Edit Node', $edit_node_link, array('attributes' =&gt; array('target' =&gt; '_blank'))),
           'message' =&gt; "&lt;em&gt;" . $row_message . "&lt;/em&gt;",
                ),
           'class' =&gt; array($row_class),
  );


Finally, after the $rows array has been defined with all the data I need I am building the table with this:

$form['table'] = array(
    '#theme' =&gt; 'table',
    '#header' =&gt; $header,
    '#rows' =&gt; $rows,
    '#empty' =&gt; 'There are no product nodes found',
);
$form['pager'] = array(
    '#markup' =&gt; theme('pager')
);


Does anyone have an ideas as to where I'm going wrong with the pager?

(Full Form Code is available here: http://pastebin.com/bna1g1iV)

Thanks,
I would add this as a comment if I could. Looking at your code, it looks like you're only adding rows to $rows is $part['wtcr_sku'] is an empty string (line 258). It's possible you could be filtering out rows because of that.