So, what I need to do is to add html table, which will output some database info, on the product page (I'm using Ubercart module). Now, I know how to make such a table (programmatically) and how to create new node and how to display this table in that node but I don't know how to put that table in the already existing node page (product page in this case) without messing with the already existing data.

Comments

sagar ramgade’s picture

Hi,

You can use hook_nodeapi with case 'view', for more info :
http://api.drupal.org/api/drupal/developer!hooks!core.php/function/hook_...

Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form

Drug-pal’s picture

Yeah, that should probably do the trick, thanks. But can you tell me how to make the content to display in the main page content instead of the top of the page where every echo is displayed? I'm aware of DSM option but I need a content display such as echo or in this case, html table, next to already existing page/node content.

jaypan’s picture

You return a value, not echo it.

Contact me to contract me for D7 -> D10/11 migrations.

Drug-pal’s picture

I already tried that and nothing happens:

case 'view':
       
         $message = "<p>Hello</p>";
        return $message;
      
     break;

Was it meant to work that way at all, to allow a simple content echo? Or do I need to use something like:

$node->content['my_additional_content'] = array(
'#value' => theme('module_my_additional_content, $additional_content),
'#weight' => 10,
);

jaypan’s picture

Sorry, I missed the point about hook_nodeapi(). In this case, you don't return a value, you just add your data to the $node->content array, as you have shown in your second example.

Contact me to contract me for D7 -> D10/11 migrations.

Drug-pal’s picture


function module_name_user_page($account) {
  $header = array('Node ID', 'Title', 'Type', 'Terms', 'Created');
  $rows = array();

  $results = db_query("SELECT * FROM {node} ORDER BY promote DESC, sticky DESC, created DESC");

  while ($node = db_fetch_object($results)) {
    $termlist = taxonomy_node_get_terms($node->nid);
    $terms = array();
    foreach ($termlist as $key => $value) { $terms[] = $value->name; }
    $rows[] = array($node->nid,
                    l($node->title, 'node/'. $node->nid .'/edit'),
                    $node->type,
                    implode(' | ', $terms),
                    format_date($node->created),
                );
   }
  return theme('table', $header, $rows);
}

The above code is located at the "module_name.pages.inc" and it works together with hook_menu function in "module_name.module" and creates the menu tab and the content for it which is the html table and the SQL data in it.

Now, how could I modify this code to make it do the same thing as described above but in this case, the table would be on the product page, beneath the product info? I am using nodeapi and view case but I just cannot modify the above code to do what I want. Whatever I try I get error or no response at all.

jaypan’s picture

Are you putting the hook in your .module file? All hooks have to go in that file.

Contact me to contract me for D7 -> D10/11 migrations.