I have a working block of php code that runs inside a Drupal 7 Page:
<?php
$my_database= array(
'database' => 'mydb',
'username' => 'xxxxxx', // assuming this is necessary
'password' => 'xxxxxx', // assuming this is necessary
'host' => 'localhost', // assumes localhost
'driver' => 'mysql', // replace with your database driver
);
Database::addConnectionInfo('database_db', 'default', $my_database);
db_set_active('database_db');
$sql = "SELECT tcol1, tcol2 FROM mytable LIMIT 10";
$result = db_query($sql);
$header = array('Col1', 'Col2');
$rows = array();
if ($result) {
while ($row = $result->fetchAssoc()) {
$row= array($row['tcol1'],$row['tcol2']);
$rows[] = $row;
}
}
db_set_active();
print_r($rows);
$output= theme('table', $header, $rows);
?>
This piece of code works fine and print_r() prints all the data I asked for. The odd thing is that the theming fails totally, showing nothing. I have done some experimentation:
$output= theme('table', $header, $rows);
echo theme('table', $header, $rows);
print theme('table', $header, $rows);
but all of them fail, showing nothing or disrupting drupal globally. How can I show my data in a nice table? I want to avoid writing html code and instead rely on Drupal theming.