Page 1 of 1

db access in CMSMS 2

Posted: Wed Oct 05, 2016 2:37 pm
by ggblake
Here's my UDT called UserListing
$gCms = cmsms();
$db = $gCms->getDb();
$sql = "SELECT * FROM " . cms_db_prefix() . "module_feusers_users";
$dbresult = $db->Execute($sql);
$count = $dbresult ->RecordCount();
$result = array();
while($dbrow = $dbresult->FetchRow()) {
$result[] = $dbrow;
}



$smarty ->assign(result,$result);
$smarty ->assign(count,$count);

and my page:
{UserListing}
<p>{$count} records on file</p>
{foreach from=$result item='entry'}
<p>Email:{$entry.email}</br>
{/foreach}

$count shows correctly so I know result is being passed as I get
the correct number of lines from the loop
But the loop shows no $entry.email or any other field

What am I missing ?

Re: db access in CMSMS 2

Posted: Wed Oct 05, 2016 2:55 pm
by Jo Morg
Try the following to see what is inside {$entry}...

Code: Select all

{foreach from=$result item='entry'}
{$entry|print_r:1}

Re: db access in CMSMS 2

Posted: Wed Oct 05, 2016 3:04 pm
by ggblake
Here's 1 record from the loop:
Array ( [id] => 134 [username] => Anderson [password] => ---------------------------------------------- [createdate] => 2014-07-31 20:38:21 [expires] => 2014-07-31 23:59:59 [nonstd] => 0 [disabled] => 0 [salt] => --------------------------------------[force_newpw] => 0 [force_chsettings] => 0 )

Re: db access in CMSMS 2

Posted: Wed Oct 05, 2016 3:18 pm
by ggblake
<p>User:{$entry['username']} ID:{$entry['id']} </br>
WORKED !!!

Thanks so much. I've spent hours trying to figure it out

Re: db access in CMSMS 2

Posted: Wed Oct 05, 2016 4:10 pm
by Jo Morg
In Smarty you can use both the PHP array notation and the Smarty dot notation to access arrays:

Code: Select all

{$entry['username']} = {$entry.username} 
Apparently you were trying to get data that wasn't there to begin with.