I need to access individual elements of a node in my module I have the following query that fetches all the nodes of a certain type.

function shop_home_page() {
  $render = array();  
  $sql = 'SELECT nid FROM {node} n WHERE n.type = :type AND n.status = :status';
  $result = db_query($sql,
    array(
      ':type' =&gt; 'music_albums',
      ':status' =&gt; 1,
    )
  );

  foreach ($result as $row) {
    $node = node_load($row-&gt;nid);
    $render['my_list'][] = node_view($node, 'teaser');       
   }     
  return $render;
}



How do I display in my page node elements such as $node-title, $node-body? I tried as $render['my_list'][] = node-&gt;title but it doesn't seem to work.
I also need to add a form with a buy button to each element. How do I attach it?
1) You can use code like the following:

$render['my_list'][] = array('#markup' =&gt; '&lt;div&gt;'.$node-&gt;title.'&lt;/div&gt;');
$render['my_list'][] = array('#markup' =&gt; $node-&gt;body['und'][0]['value']);


2) Forms can be added similarly to node_view():

$render['my_list'][] = drupal_get_form('mymodule_buy_form_'.$node-&gt;nid, $node-&gt;nid);


I'm assuming you want the forms built with a single function, but with different id-s to work correctly (attached $node-&gt;nid for that). I also added an extra argument ($node-&gt;nid) since you may want to add it to every form in a hidden field to determine which form got submitted. Then you use hook_forms() to get the same builder function called for all the buying forms:

function mymodule_forms($form_id, $args) {
  $forms = array();
  if (strpos($form_id, 'mymodule_buy_form_') === 0) {
    $forms[$form_id] = array(
      'callback' =&gt; 'mymodule_buy_form',
    );
  }
  return $forms;
}


The form builder function for this example:

function mymodule_buy_form($form, &amp;$form_state, $nid) {
  $form = array();
  $form['nid'] = array(
    '#type' =&gt; 'hidden',
    '#value' =&gt; $nid,
  );
  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
  );
  return $form;
}


And a submit handler:

function mymodule_buy_form_submit($form, &amp;$form_state) {
  drupal_set_message('Form for node '.$form_state['values']['nid'].' submitted.');
}