Create a simple module to retrieve record from database? I need to create a simple module to fetch some record from database related to a node.

I have product nodes and users who makes bids in this product. Then at the time I load a product I need to retrieve all bids in this product to show them in a block.

I need some start guide/documentation to do it.

This is my first module attempt and this is the code I start working with: no error yet but it doesn't print out the values I need.

function myModule_load($node){

$result = db_query("SELECT * FROM {uc_auction_bids} WHERE nid = :nid", array(':nid' =&gt; 258,));
$record = $result-&gt;fetch(); 

// print the fields/values of $record
print('&lt;pre&gt;');
print_r($record);
print('&lt;/pre&gt;');


}

Any help for creating this simple module, please?

I just need to know which is the right function/hook where I can fetch the data from the database, and prepare the data to create the block.
The Creating modules tutorial covers block creation: implementation of hook_block_info() to declare your block, implementation of hook_block_view() to generate the block content, usage of theme() to format retrieved records and usage of user_access() to check user permission before giving him/her access to the information

The only missing information is the menu_get_object() function which you can use to retrieve the currently displayed node (if any).

function myModule_block_view($delta) {
  if (($node = menu_get_object()) &amp;&amp; ($node-&gt;type === 'product')) {
    $results = db_query("SELECT * FROM {uc_auction_bids} WHERE nid = :nid", array(':nid' =&gt; $node-&gt;nid));
    $records = $results-&gt;fetchAllAssoc('bid');

    $content = ... // Format records here...

    return array(
      'subject' =&gt; t('Bids'),
      'content' =&gt; $content
    );
  }
}


A more complex solution, but a flexier one, would be to expose the uc_auction_bids table to views using a hook_views_data() implementation. You could then create a block display using a contextual filter to retrieve the current node ID.