OK, I think I follow now. The database results go into an array; how they get there is your problem. Then you $smarty->assign()and use Smarty's section syntax to iterate/display the array. So I'm basically back where I started.
Meanwhile I've been looking at the PEAR $db->getAssoc method to see if that would save a step. Anyway you asked for a print_r of the PEAR db resultSet object, so here's my source
echo "I am {$_SERVER['PHP_SELF']}<br />";
$smarty = new SmartyDemo;
require_once 'DB.php'; // PEAR database access class
extract( parse_ini_file("/data/htdocs/sdny/dev/hal.cfg"));
$dsn = "$driver://$username:$password@$host/$database";
$db = DB::connect($dsn);
if (DB::isError($db)) { die ($db->getMessage()); }
$sql = "select judge_id,lastname, firstname from judges order by lastname limit 5";
// with the DB::getAssoc() method
$data = $db->getAssoc($sql);
if (DB::isError($data)) { die ($data->getMessage());}
$result_obj = $db->query($sql);
print "<pre>Associative array:\n";
print_r($data);
print "As a PEAR result object:\n";
print_r($result_obj);
print "</pre>";
$smarty->assign("data",$data);
$smarty->display('index.tpl');
?>
and here's my output.
I am /dev/smarty/demo.php
Associative array:
Array
(
[3] => Array
(
[0] => Baer
[1] => Harold
)
[7] => Array
(
[0] => Batts
[1] => Deborah
)
[23] => Array
(
[0] => Berman
[1] =>
)
[76] => Array
(
[0] => Brieant
[1] => Charles
)
[49] => Array
(
[0] => Buchwald
[1] => Naomi
)
)
As a PEAR result object:
db_result Object
(
[dbh] => db_mysql Object
(
[connection] => Resource id #7
[phptype] => mysql
[dbsyntax] => mysql
[prepare_tokens] => Array
(
)
[prepare_types] => Array
(
)
[num_rows] => Array
(
[8] => 5
[9] => 5
)
[transaction_opcount] => 0
[autocommit] => 1
[fetchmode] => 1
[_db] => interpreters
[_debug] =>
[_default_error_mode] =>
[_default_error_options] =>
[_default_error_handler] =>
[_error_class] => DB_Error
[_expected_errors] => Array
(
)
[features] => Array
(
[prepare] =>
[pconnect] => 1
[transactions] => 1
[limit] => alter
)
[errorcode_map] => Array
(
[1004] => -15
[1005] => -15
[1006] => -15
[1007] => -5
[1008] => -17
[1046] => -14
[1050] => -5
[1051] => -18
[1054] => -19
[1062] => -5
[1064] => -2
[1100] => -21
[1136] => -22
[1146] => -18
[1048] => -3
)
[type] =>
[prepared_queries] =>
[prepare_maxstmt] => 0
[last_query] => select judge_id,lastname, firstname from judges order by lastname limit 5
[fetchmode_object_class] => stdClass
[options] => Array
(
[persistent] =>
[optimize] => performance
[debug] => 0
[seqname_format] => %s_seq
)
[dbh] =>
[dsn] => Array
(
[phptype] => mysql
[dbsyntax] => mysql
[username] => somebody
[password] => very_secret
[protocol] => tcp
[hostspec] => hal
[port] =>
[socket] =>
[database] => interpreters
)
)
[result] => Resource id #9
[row_counter] =>
[limit_from] =>
[limit_count] =>
)
You see that the PEAR Result is more metadata than data. You call the fetchXXX() and getXXX() methods on the result object to get to the actual data.
If you look at the data structure that getAssoc() returns, you'll see it's a 2-dimensional array where the first column supplies the keys and the values are an array containing the data from the remaining columns. I bet you could get Smarty to loop through that. Then I'd be saving this extra step and life would be beautiful. So I'm trying to get the hang of Smarty's section looping thing.
Thank you again.