JHtmlList/genericordering
From Joomla! Documentation
< API16:JHtmlListRevision as of 21:57, 13 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)
Revision as of 21:57, 13 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Returns an array of options
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
static genericordering($sql, $chop= '30')
Parameter Name | Default Value | Description |
---|---|---|
$sql | $sql SQL with ordering As value and 'name field' AS text | |
$chop | '30' | $chop The length of the truncated headline |
Returns[edit]
array An array of objects formatted for list processing
Defined in[edit]
libraries/joomla/html/html/list.php
Importing[edit]
jimport( 'joomla.html.html.list' );
Source Body[edit]
public static function genericordering($sql, $chop = '30')
{
$db = &JFactory::getDbo();
$options = array();
$db->setQuery($sql);
$items = $db->loadObjectList();
// Check for a database error.
if ($db->getErrorNum()) {
JError::raiseNotice(500, $db->getErrorMsg());
return false;
}
if (empty($items)) {
$options[] = JHtml::_('select.option', 1, JText::_('JOption_Order_First'));
return $options;
}
$options[] = JHtml::_('select.option', 0, '0 '. JText::_('JOption_Order_First'));
for ($i=0, $n=count($items); $i < $n; $i++)
{
if (JString::strlen($items[$i]->text) > $chop) {
$text = JString::substr($items[$i]->text,0,$chop)."...";
} else {
$text = $items[$i]->text;
}
$options[] = JHtml::_('select.option', $items[$i]->value, $items[$i]->value.' ('.$text.')');
}
$options[] = JHtml::_('select.option', $items[$i-1]->value+1, ($items[$i-1]->value+1).' '. JText::_('JOption_Order_Last'));
return $options;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />