RE: [SMARTY] ADOdb with Smarty (and an array question throw in to boot!)
| From: | Jonathan Chum | Date: | Thu, 16 Dec 2004 16:58:22 +0000 |
| Subject: | RE: [SMARTY] ADOdb with Smarty (and an array question throw in to boot!) | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12049@lists.php.net to get a copy of this message | ||
What I generally do with ADOdb is:
$result = $adodb->query("SELECT surname, fname FROM table");
while (!$result->EOF)
{
$data[] = $result->fields;
}
$smarty->assign('data', $data);
In my Smarty template, I would loop through the result set like so:
<!---section name="set" loop=$data--->
<!---$data[set].surname---> <!---$data[set].fname---> <BR>
<!---/section--->
Using $result->fields, the data pulled from the database is returned as
associate array which is why I can call them directly in the Smarty
template.
BTW, try $data["SURNAME"] because without the quotes, PHP is interepreting
it as a constant. Depending on the php.ini configuration, it will try to
evaluate as a constant if you don't have the double quotes around it.
-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Robert
Sent: Thursday, December 16, 2004 11:29 AM
To: smarty-general@lists.php.net
Subject: [SMARTY] ADOdb with Smarty (and an array question throw in to
boot!)
Q1: Is there a faster way of doing this?
while ($data = $rs->FetchRow()) {
$surname[] = $data[0];
$fname[] = $data[1];
$userid[] = $data[2];
$email[] = $data[3];
$profile[] = $data[4];
$position[] = $data[5];
}
Q2: I ran the above using $data[SURNAME] for $data[0] and it runs but I get
"Use of undefined constant" errors in my logs. When I do a "print_r($data)"
my structure looks like this:
Array([0]=>HICKS[SURNAME]=>HICKS[1]=>ROBERT[FIRST_NAME]....)
Do I need to use the arrays position number [0]? I would like to use
[SURNAME] because it is easier to understand when you see the code.
Robert
--
Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php