0
$title = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", 1));

with this code i can get title from node with id == 1. But how can i load all node titles with specific content type?

$title = db_result(db_query('SELECT title FROM {node} WHERE type = %s', $content_type));

Please correct my code to get all node titles from specific content type and how to limit them by 20 items for example?

  • What version of Drupal are you using? The Drupal 7 syntax is different than Drupal 6 syntax. – keithm Nov 20 '11 at 14:53
7
$result = db_query_range("SELECT title FROM {node} WHERE type = '%s'", $content_type, 0, 20);
$titles = array();
while ($row = db_fetch_object($result)) {
  $titles[] = $row->title;
}

http://api.drupal.org/api/drupal/includes--database.inc/group/database/6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.