Returning an indexable array from a UDT [solved]

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
crankshaft
Forum Members
Forum Members
Posts: 57
Joined: Sun Mar 25, 2007 7:42 am

Returning an indexable array from a UDT [solved]

Post 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

:-)
Last edited by crankshaft on Tue Jan 20, 2009 7:12 am, edited 1 time in total.
User avatar
aln_cms
Forum Members
Forum Members
Posts: 88
Joined: Mon Jan 08, 2007 7:09 pm
Location: Ireland

Re: Returning an indexable array from a UDT

Post by aln_cms »

hey, I'd like to help - but I'm a little lost.

what's not working ?
--
Alan Ryan
Lead Developer
CodeCrunchers Internet Software Development - Ireland
http://www.codecrunchers.ie
crankshaft
Forum Members
Forum Members
Posts: 57
Joined: Sun Mar 25, 2007 7:42 am

Re: Returning an indexable array from a UDT

Post 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.
Post Reply

Return to “Developers Discussion”