Is there an easy way to use Drupal's API to easily pull a node's data if you know its number?

I've built two custom node types which have a one-to-many relationship, like "shuttle flight" and "crew member", and tied them together with a simple relationships table. I have a nice node template "node-flight.tpl.php" in my theme, and whenever you view a flight node I want to be able to include all of the crew, including data pulled from their nodes. I can write the SQL to get the relationships and each crew member's node number, but then is there an easy way to have Drupal go get the latest revision of those nodes, even just one at a time? And if so, how is it returned? I can figure out that SQL too, but I'm hoping I don't have to.

Thanks in advance!

Comments

heine’s picture

You can use the function node_load eg

$nid = 1;
$node = node_load( $nid );

--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

Papayoung’s picture

This is perfect for what I want to do. I had spent some time at api.drupal.org, but without knowing the name of the function in advance I could only have found it by brute-force search.

Thanks!

rszrama’s picture

For future reference, when searching the API you should start checking for anything node related by typing 'node' in the search box and letting it list all the functions there. I think you'll get the hang of finding the write function fairly quickly, especially the more you see the list. There was also an extremely helpful cheatsheet published at a website a while back that I can't find the link to right now... can someone else tack it in here?

heine’s picture

http://www.inmensia.com/articulos/drupal/cheatsheet4.7.html (the picture).

Warning: most of the form_[element] functions such as form_select are not available in 4.7
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

skor’s picture

Good timing. I needed this info too.