Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By czheng on
Hi folks,
A quick question that I'm hoping has a quick solution. I've got a handful of custom views on my site that I create using DB queries like this one:
$display_type = "'content_journal_issue'";
$sql = "SELECT * FROM node WHERE node.type LIKE $display_type ORDER BY node.created DESC";
$result = db_query($sql);
while($anode = db_fetch_object($result)) {
$cissue .= node_view(node_load(array('nid' => $anode->nid)), 1);
print "<div class='issue-view'>" . $cissue . "</div>";
Is there an easy way to get these results paged using Drupal's paging system? I've poked around for a bit on the forums but haven't found an answer...
Thanks in advance,
craig
Comments
Does this help?
http://api.drupal.org/api/4.7/function/pager_query
Note: I don't actually have any experience using it though :)
--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Check out
Check out pager_query():
http://api.drupal.org/api/4.7/function/pager_query
----------------------
Current Drupal project: http://www.ubercart.org
http://api.drupal.org/api/4.7
http://api.drupal.org/api/4.7/function/tablesort_sql
This will let sorting and limits work.
http://api.drupal.org/api/4.7/function/pager_query
This will perform a limit/top query.
http://api.drupal.org/api/4.7/function/theme_table
This has the documentation on how you need to set up your $header and $rows arrays.
http://api.drupal.org/api/4.7/function/theme_pager
This is used to do the pager links on the bottom.
Here's an example page snippet that I use on one of my testing sites:
All columns with a field attribute in the header are sortable. The tablesort_sql line makes it work.
Hope this is enough to go by.
Got it working, thanks very
Got it working, thanks very much.
Great post!
Great post! Very instructive and helpful. Glad I found it. Thank you!