Hi,
This is main function its return the final ui(Html design) output in that i need to include pagination how to do that using
drupal

  function allsearch_show(){
   $output= subjectSearch();// this function getting data from db and returns the output in ui(Html design) 
                                          design format.
  $output.=collectionSearch();// this function getting data from db and returns the output in ui(Html design) 
                                          design format.
  $output.=periodicalSearch();// this function getting data from db and returns the output in ui(Html design) 
                                          design format.
  $output.=referenceSearch();// this function getting data from db and returns the output in ui(Html design) 
                                          design format.
   if($output== NULL){
  $output = "<h3>No Search Results Found</h3>";
 }
 return $output;   
}

thanks

[Edited to add <code> and <code> tags; nevets]

Comments

nevets’s picture

Standard Drupal pagination is not going to work for you since it relies a single query returning a result set and limiting the number of records that are returned (ie one page)

aangel’s picture

He could throw his data into a temporary table then he'd be able to use the built in pager. When the session is closed the temporary table will automatically be dropped by mysql.

Much better than making one's own pager mechanism, imo.

http://dev.mysql.com/doc/refman/5.1/en/temporary-table-problems.html

http://dev.mysql.com/doc/refman/5.1/en/create-table.html

http://dev.mysql.com/doc/refman/5.1/en/insert-speed.html

Andre'

aangel’s picture

this isn't working for me. The pager mechanism doesn't like that subsequent calls to it can't find the temporary table.

marcexx66’s picture

There are too many things that won't work in drupal. Pagination, load an external application etc...

definetly drupal s**cks

Drupal vale callampa!!

markpetherbridge’s picture

I love the fact that your signature completely contradicts your statement.

alan d.’s picture

You could always use a number of unions to do the queries in a single SQL statement.

You can also create your own pager function to handle the process. The one below accepts an array rather than sql.

<?php
function showcase_array_pager($data, $limit = 10, $element = 0) {
  global $pager_page_array, $pager_total, $pager_total_items, $pager_parameter_name;
  $key = (empty($pager_parameter_name)) ? 'page' : $pager_parameter_name;
  
  $page = isset($_GET[$key]) ? $_GET[$key] : '';
  $args = func_get_args();
  $args = array_slice($args, 4);
  if (isset($args[0]) && is_array($args[0])) {
    $args = $args[0];
  }
  // Convert comma-separated $page to an array, used by other functions.
  $pager_page_array = explode(',', $page);
  // We calculate the total of pages as ceil(items / limit).
  $pager_total_items[$element] = count($data);
  $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
  $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
  return array_slice($data, $pager_page_array[$element] * $limit, $limit, TRUE);
}
?>

This isn't a good approach for complex large searches, for example using fully loaded nodes or themed output, but if you set up a proxy, even just a simple nid array, the overhead is reduced significantly.

In this case, select a key that references the result, throw these into the array, and then run this against the array pager. Once you get the pager results, theme these up.

Drupal may not be the easiest CMS out there to program, and it often requires you to get your hands dirty, but it is very powerful. Be nice to the hundreds of people that do thousands of hours of work for free.


Alan Davison
www.caignwebs.com.au

Alan Davison
jwilson3’s picture

I just implemented the array_pager() function mentioned above in my code and i dont know how but the pager generated the standard Drupal pager pages (ie, 1 2 3 4 5 6 ...) at the bottom of the page below my table (I'm using TAPIr).

Now if that's not Drupal magic, I don't know what is!

How does that work? Where is the code in the array_pager() function that says create that pager stuff?

Hmmm, i guess the globals are the key here.

 global $pager_page_array, $pager_total, $pager_total_items, $pager_parameter_name;

http://api.drupal.org/api/global/pager_page_array
http://api.drupal.org/api/global/pager_total
http://api.drupal.org/api/global/pager_total_items

GENIUS!

Only thing I couldn't find was $pager_parameter_name.... not sure what that does or where it comes into play.

Now, if only it worked correctly, the pager url is one digit behind the named link in the footer (eg link says 2, but the url is "?page=1")

James Wilson
Elementalidad

alan d.’s picture

I assumed that there was one Get variable per pager, but Drupal uses one variable like page=3,4,5,3 the numbers being the different pager. You can attempt dropping this part of the code completely.

While not part of the base system, the pager follows an adapter pattern so is easy to implement new pagers.


Alan Davison
www.caignwebs.com.au

Alan Davison
alan d.’s picture

The first function above can be replaced with this one.

<?php

function pager_array_splice($data, $limit = 10, $element = 0) {
  global $pager_page_array, $pager_total, $pager_total_items;
  $page = isset($_GET['page']) ? $_GET['page'] : '';

  // Substitute in query arguments.
  $args = func_get_args();
  $args = array_slice($args, 4);
  // Alternative syntax for '...'
  if (isset($args[0]) && is_array($args[0])) {
    $args = $args[0];
  }

  // Convert comma-separated $page to an array, used by other functions.
  $pager_page_array = explode(',', $page);

  // We calculate the total of pages as ceil(items / limit).
  $pager_total_items[$element] = count($data);
  $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
  $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
  return array_slice($data, $pager_page_array[$element] * $limit, $limit, TRUE);
}
?>

This removes my custom "page" query parameter hack from an old project. Both should still work :)


Alan Davison
Julien L.’s picture

Hey,

Thank you for posting this code here, it helped me a lot and seems to be working well in my project.
I just don't manage to understand what this part of the code is doing, as the $args variable is not used anywhere later.

 // Substitute in query arguments.
  $args = func_get_args();
  $args = array_slice($args, 4);
  // Alternative syntax for '...'
  if (isset($args[0]) && is_array($args[0])) {
    $args = $args[0];
  }
 

Thanks,
Julien

alan d.’s picture

Must have been left overs from something custom I was doing :)

I have moved the clean example to the developer handbook at Paging non-SQL data. Note that there was one minor API change in Drupal 7, the default pager changed to 9 items rather than 10.


Alan Davison