I have made custom node "project". Inserted the values in the database. Now I want to create a module, which on the user criteria displays project information. For instance if the user wants to view the project from a certain customer, he sees a tabular result. I can’t generate views. I was reading the book and I got the hang of templates. But somehow nothing is displayed. I don’t understand how to display attributes of a table. The query at hook_load works fine, fetches the data. Either the hook_view has issues or I am not implementing it right. Can somebody guide me please ?

Comments

Raf’s picture

If I understand correctly, you want to create a node type (different than the default "page" and "story") and create a view from it. What I don't understand, is why you'd be doing all that in code. Can't you just use CCK and Views UI for this?

Ambreen Darjat’s picture

Yeah I can. Since it is a university project related to programming styles..I have to learn the coding methods.

Ambreen Darjat’s picture

I have got the hang of creating nodes..now just need a proper tabular display (as those of reports)

Raf’s picture

What you're trying to do is very, very, very easy in Drupal... if you use the UI. Coding it's a whole lot trickier, and you're making things unnecessarily difficult that way.

That said, if you need to do it programmatically, and if you don't NEED to use the Views API, I'd go for a combination of the following:

  1. Create a function that takes an array of node IDs to display
  2. In that function, set up the main, top parts of the table (possible headers, the table tag, etc)
  3. Loop through that array and do a node_load on each ID
  4. For each iteration, create a row (with tr) and show the data you need. You can access it using the results of node_load as an object (krumo, print_r or var_dump it to take a peek inside that object)
  5. Finish with closing everything
  6. Return the resulting HTML
  7. I assume you're using hook_menu to create each menu item, so in each callback where you require the table, get all node IDs you need to display and pass it to that function

A couple of remarks on this:

  • It's far from the most optimal solution. Node_load makes life a WHOLE lot easier for you as a programmer, but it's a very heavy process. It's good if your list shows only a few results. If it's displaying a couple of thousands, though, you'll be in trouble
  • Seeing as this is a matter of displaying things, it might be best to make that function a theme_function, so people can overwrite it in template.php if they ever need to. I guess for your project, it doesn't matter much, but it's a good habbit to take on. You'll be glad you make those distinctions later on