Wednesday, 29 August 2012

How to Fetch Data from a table in Drupal 7

Step 1: Write a query into a Query String

$queryString = "select title from {node} where nid=:nid";

Step 2: Execute the Query using db_query() function.

$queryResult=db_query($queryString, array(':nid'=>$nid));

Step 3: Fetch the data into an Object from the Result using fetchObject() function.

$dataObject = $queryResult->fetchObject();


Print the values using any one of PHP print commands (echo / print / print_r ...). In the above example "nid=:nid" is used as an Argument

No comments:

Post a Comment

Thank you so much for providing your valuable feedback. I will will look into them and update my skills & technologies accordingly.