I'm building a custom module for webform and I want to get only a title for a specific content type.

In phpMyAdmin with sql query I've managed to sort what titles I need. This is the SQL query:

SELECT title FROM `node` WHERE TYPE = 'outlets' AND uid

How can I wrap this into db_query() ?


You can read more about db_query() here.

$result = db_query("
  SELECT title
  FROM {node} n
  WHERE n.type = :type
    AND n.uid =:uid
", array(':type' => 'outlets', ':uid' => $uid));

foreach ($result as $record) {
  // Perform operations on $record->title, etc. here.
  // in this example the available data would be mapped to object properties:
  // $record->nid, $record->title, $record->created
| improve this answer | |

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.