PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty2/plugins/function.html_dboptions.php

http://zoop.googlecode.com/
PHP | 34 lines | 14 code | 4 blank | 16 comment | 1 complexity | c8fd3cce77ef3c4a6a2f5761331f89cd MD5 | raw file
 1<?php
 2/**
 3 * Smarty {html_dboptions} function plugin
 4 *
 5 * Type:     function<br>
 6 * Name:     html_dboptions<br>
 7 * Input:<br>
 8 *           - name       (optional) - string default "select"
 9 *			 - tablename  (required 
10 *           - selected   (optional) - string default not set
11 * Purpose:  Pulls a list of options from the database and prints the list of <option> tags generated from
12 *           the passed parameters
13 * @param array
14 * @param Smarty
15 * @return string
16 * @uses smarty_function_html_options()
17 */
18
19function smarty_function_html_dboptions($params, &$smarty)
20{
21    require_once $smarty->_get_plugin_filepath('function','html_options');
22    
23    $tableName = $params['tablename'];
24    if( isset($params['namefield']) )
25    	$nameField = $params['namefield'];
26    else
27    	$nameField = 'name';
28    
29    $params['options'] = SqlFetchSimpleMap("SELECT id, :nameField AS name FROM :tableName:identifier order by id", 'id', 'name', 
30							array('nameField:identifier' => $nameField, 'tableName' => $tableName));
31    
32    return smarty_function_html_options($params, $smarty);
33}
34?>