I have an entity called announcement, and I have a page (user/%/announcement) where I display a table of three columns (name of entity,an edit entity link and an delete entity link).
function announcements_user($account) {
$uid = $account->uid;
$return = '';
$total = 0;
$i=0;
$pid = array();
$text = array();
$query = db_select('announcements','a')->extend('PagerDefault');
$query->fields('a',array('pid','value'));
$query->condition('uid', $uid);
$result = $query->execute();
foreach($result as $row) {
$pid[] = $row->pid;
$text[] = $row->value;
$total++;
}
$return .= '<table border="1">
<tr>
<th>Announcement</th>
<th>Edit</th>
<th>Delete</th>
</tr>';
while ($total) {
$return .= '<tr>';
$return .= '<td><a href="'.$base_url.'/announcement/'.$pid[$i].'">'.substr($text[$i],0,10).'......</a></td>';
$return .= '<td><a href="'.$base_url.'/announcement/edit/'.$pid[$i].'">Edit</a></td>';
$return .= '<td><a href="'.$base_url.'/announcement/delete/'.$pid[$i].'">Delete</a></td>';
$return .= '</tr>';
$i++;
$total--;
}
$return .='</table>';
$return .='<br>';
$return .='<a href ="'.$base_url.'/announcement/add">Add Announcement</a>';
return $return;
}
Now my problem is that keeping this format of tabular structure, how do I display my result in a paginated format with 5 announcements per page? I have seen pager.inc for Drupal 7 and howto-print-out-the-pagination-for-entityfieldqueries link, but I just can't figure out how to apply them to my case.