Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By mrbkonline on
Hi,
I'm new to Drupal and web development and need some help.
I populated a mySQL database table manually and I want to check if I can read the rows from it.
I wrote the following test code to iterate through the rows and print the results.
$sql = "SELECT * FROM {yrtrCandidates}";
$result = db_query($sql);
while ($data = db_fetch_object($result))
{
print $data;
}
However, I get the following output:
ObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObject
ps my table has 25 rows and the word object is written 25 times (above).
Could anyone tell me what I am doing wrong?
thanks in advance for your help!
Comments
Print Object and Data
Look at this code:
$data = db_fetch_object($result)
The $data consists of all fields in an array type. To print:
1. The array then use: print_r($data);
2. Only specific field: print $data->fieldname;
Replace above "fieldname" with the real field name from your {yrtrCandidates} table.
that works!
thank you very much, that works great!