Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

missing data

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
lesmith
Smarty Rookie


Joined: 19 Sep 2003
Posts: 34

PostPosted: Wed Sep 24, 2003 9:12 pm    Post subject: missing data Reply with quote

Hi peeps im a newbie to smarty so please be gentle. I have set up smarty to use PEAR as well. Now I cant understand why some data is not being displayed on a template when I know it is there. Here is my below script. Can someone please tell where Im going mad.

tutorial.php // testing page

include_once("config.inc.php");
include_once(APP_INC_PATH . "class.template.php");
$tpl = new Template_API();
$tpl->setTemplate("tutorial.tpl.html");

include_once("DB.php");
/////////////////////////////////////////////////////////////////////////////
$dsn = $DB_dbType . "://" // Build a DSN string (Data Source Name)
. $DB_user . ":" // Required by DB::connect()
. $DB_pass . "@"
. $DB_host . "/"
. $DB_dbName;

$db = DB::connect($dsn, TRUE); // Creates a database connection object in $db

if (DB::isError($db)) { // Check whether the object is a connection or
// an error.
die($db->getMessage()); // Print out a message and exit if it's
// an error object.
}


$stmt = "select * from people";
$people = $db->getAssoc($stmt);

$tpl->assign("people", $people);

// Display Tempate //
$tpl->displayTemplate();

$db->disconnect(); // Close the connection.

The array $people is full of data. I know this because I have done a simple print_r($people) and it returns a full array.

Simple template to display data.
tutorial.tpl.html ////////////////// simple tpl

<table border="1" cellspacing="0" cellpadding="5">
<tr>
<td>id</td>
<td>firstname</td>
<td>surname</td>
</tr>
{section name=i loop=$people}
<tr>
<td>{$people[i].id}</td>
<td>{$people[i].firstname}</td>
<td>{$people[i].surname}</td>
</tr>
{/section}
</table>

This should be working fine. I know the $people has data in it but its not displaying it.

Can anyone see the reason why.

Please help if you can.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Sep 24, 2003 9:31 pm    Post subject: Reply with quote

I'm not 100% familiar with Pear::DB but I don't think that getAssoc() works the way you have it setup because it doesn't return an array of associative arrays, but instead returns an associative array where the key is the first field in your return set and the data is an indexed array. Thus, your references to fields (people[i].firstname, etc) don't actually point to anything (because the row doesn't have an associative element with the key "firstname").

Like I said, I'm not up on Pear::DB, but perhaps you need to set setFetchMode() first? Or use GetAll()?

EDIT: This tutorial (under the section "Handling More Complex Result Sets") provides more details.

Synopsis: use $people = $db->getAll($stmt, DB_FETCHMODE_ASSOC);
Back to top
View user's profile Send private message
lesmith
Smarty Rookie


Joined: 19 Sep 2003
Posts: 34

PostPosted: Wed Sep 24, 2003 9:43 pm    Post subject: Reply with quote

Thanks Boots

I have taken 90% of this from the ONLamp.com tutorial. And like you this is a first for me using PEAR. Im not so sure if I should use it. I have been at this nearly all night what with setting up PEAR etc.

But thank you I have re-read the tut and found this extra bit

$people = $db->getAll($stmt, DB_FETCHMODE_ASSOC);


I have now put this in and it works A1

Thakyou
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP