db access in CMSMS 2

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Locked
ggblake
New Member
New Member
Posts: 3
Joined: Wed Oct 05, 2016 2:09 pm

db access in CMSMS 2

Post 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 ?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: db access in CMSMS 2

Post by Jo Morg »

Try the following to see what is inside {$entry}...

Code: Select all

{foreach from=$result item='entry'}
{$entry|print_r:1}
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
ggblake
New Member
New Member
Posts: 3
Joined: Wed Oct 05, 2016 2:09 pm

Re: db access in CMSMS 2

Post 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 )
Last edited by Jo Morg on Wed Oct 05, 2016 4:12 pm, edited 1 time in total.
Reason: Security
ggblake
New Member
New Member
Posts: 3
Joined: Wed Oct 05, 2016 2:09 pm

Re: db access in CMSMS 2

Post by ggblake »

<p>User:{$entry['username']} ID:{$entry['id']} </br>
WORKED !!!

Thanks so much. I've spent hours trying to figure it out
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: db access in CMSMS 2

Post 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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Locked

Return to “The Lounge”