Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4534720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:18:58+00:00 2026-05-21T14:18:58+00:00

I have 3 nodes of content type ‘mycontenttype’. I’m trying to setup a sortable/pagable

  • 0

I have 3 nodes of content type ‘mycontenttype’. I’m trying to setup a sortable/pagable table with a limit of 10 items per page.

In this code, $nids only returns 3 nodes. I’m actually runnng node_load_multiple($nids) then looping through those nodes to build the $rows variable. Only 3 appear.

Problem: The pager is rendering with 4 pages.

Expectation: There should be no pager rendering because I do not have 10 nodes in the query or the count query.

Any insight would be greatly appreciated.

<?php
function mymodule_create_a_pager_table() {

  $query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort')->element('my_custom_id');
  $query->fields('n', array('nid'));

  $query->condition('n.type', 'mycontenttype');
  $query->condition('n.status', 1);

  $count_query = clone $query;
  $query->setCountQuery($count_query);

  $query->limit(10);

  $header = array(array('data' => 'Title', 'sort' => 'asc', 'field' => 'n.title'), 'column 2', 'column 3');
  $query->orderByHeader($header);

  $nids = $query->execute()->fetchCol();

  // ... building $rows array for display only here

  $output = theme('table', array('header'=> $header, 'rows' => $rows));
  $output .= theme('pager', array('element' => 'my_custom_id', 'quantity' => 10));

  return $output;
}
?>

Output

Node 1 Title | col2 val | col3 val

Node 2 Title | col2 val | col3 val

Node 3 Title | col2 val | col3 val

1 2 3 4 next › last »

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:18:59+00:00Added an answer on May 21, 2026 at 2:18 pm

    I think element should be an integer.

    Try to leave both the ->element() call and any arguments to theme(‘pager’) away.

    Also, your count query is wrong. Just don’t define it either, that will be done automatically for you. This is probably the actual reason for your problem, not the element thing.

    The count query get’s executed and the first returned value (fetchField()) is assumed to be the number of elements. Your query probably returns a nid and that is mistaken as the number. So just leave that away, and Drupal will build a correct count query automatically for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a content type appointment with a date field that references nodes of
I have several different content type nodes (videos, image galleries, stories...) that I would
I have a set of existing nodes for a content type ('foo'). Since then
Suppose I have 100 nodes in content type of product, I would like to
I have a content type that references multiple nodes, and I need a way
I have a list of items (blue nodes below) which are categorized by the
I have module that implements custom content type via NodeAPI hooks ( hook_insert ,
I have a Drupal (v6.17) Content Type which includes a Taxonomy field. I want
I've defined a custom content type - news. I also have a menu item
I have a content type (A) that references a single node of a different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.