In this tutorials i going to explain how to write the custom queries in drupal 7. The most common style of question in Drupal could be a static question. A static question is one which will be passed to the info nearly verbatim.
solely choose queries is also static. Below is the example that shows easy way of writing your custom queries :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php $output = ''; $result = db_query("SELECT nid FROM {node} WHERE whatever"); while ($row = db_fetch_object($result)) { // Load the node - You can also built the object yourself if you know which fields you need. $node = node_load($row->nid); // Put a build_mode key on the $node object $node->build_mode = 'teaser'; // Check the teaser flag and show_links flag. $teaser = ($node->build_mode != 'full') ? TRUE : FALSE; $show_links = ds_show_field('nd', $node->type, $node->build_mode, 'links'); // Use node_view to render. $output .= node_view($node, $teaser, FALSE, $links); } return $output; ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: custom module in drupal, Drupal, drupal database query, write custom query in drupal 7