Page 1 of 1

Returning an indexable array from a UDT [solved]

Posted: Mon Jan 19, 2009 1:15 pm
by crankshaft
Been struggling with this for several hours, and have trawled the forums but can't seem to find the answer.

I want to create a UDT that I can pass a parameters to,  and have it return an array which I can then index / access, something like this:

## Content Page Code ##
{get_domain server='xxx.com'}
{foreach from=$get_domain item=row}
Domain: {$row->domain}
Title: {$row->title}
Description: {$row->desc}
{/foreach}

## UDT get_domain Code ##
$server = $params['server'];
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
$result = mysql_query ("SELECT * FROM domains WHERE dom_name = '$server'");
$row = mysql_fetch_array($result);
// result = array(domain,title,desc)
global $gCms;
$smarty = &$gCms->GetSmarty();
$smarty->assign(row, $row);
## / UDT get_domain ##

I want to do a select on an external database and return the results which I can then use in the code, and I want to do it with one DB query, rather than one query for each result field.

Any sample code or help greatfully received

:-)

Re: Returning an indexable array from a UDT

Posted: Mon Jan 19, 2009 2:06 pm
by aln_cms
hey, I'd like to help - but I'm a little lost.

what's not working ?

Re: Returning an indexable array from a UDT

Posted: Mon Jan 19, 2009 11:12 pm
by crankshaft
Hi;

Well it does not appear to work at all, no code is generated on the content page, what I am looking for is some sample code of how to return variables from a UDT and be able to access them from within a content page.

If I simply echo (or print) each variable within the UDT then that's easy, but I want to return them to the requesting content page to be used on the page.