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

drupalnesia’s picture

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.

mrbkonline’s picture

thank you very much, that works great!