SQL Query Pager

Dear everyone,

I have developed this module where it retrieves all user messages from the database. The query looks like this:

global $user;  
$messages_query = db_select('pm_message', 'i')  
                            ->condition('i.recipient', $user->uid );  
$messages_query -> condition('i.deleted_from_inbox', 0, '=' ); 	
$data = $query -> fields('i', array ( 'mid' )); 
.
.
$data = $query -> orderBy('m.timestamp', 'DESC');
$data = $query -> extend('PagerDefault')->limit(3);
$data = $query -> execute();

foreach ($data as $r) {  }	

I then constructed the table header and rows like this:

$header = array(
                array('data' => t('From')),
				array('data' => t('Message')),
				);
$rows[] = array(
              array('data' => '   ', 'width' => '25%'),
              array('data' => '     ', 'width' => '25%'),);

and I added a pager like this:

$table_attributes = array('id' => 'inbox-table');
    $inbox_block = theme( 'table', array('header' => $header, 'rows' => $rows, 'attributes' => $table_attributes   ));
	$result = $inbox_block;
        $result .= theme('pager');
	return $result;

But the pager doesn’t work. I had a code somewhat similar to this in another module and it worked, it was like this:

$block['content'] = theme( 'table', array(
                           'header' => $header,
			   'rows' => $rows,
			   'attributes' => array('class' => array('mytable'))   ));
$block['content'] .= theme('pager');
return $block;

Can someone please explain to me why the pager is not working? Thank you very much in advance.

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed