API16:JHtmlList/genericordering
From Joomla! Documentation
Description
Returns an array of options
<! removed transcluded page call, red link never existed >
Syntax
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
array An array of objects formatted for list processing
Defined in
libraries/joomla/html/html/list.php
Importing
jimport( 'joomla.html.html.list' );
Source Body
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 transcluded page call, red link never existed >
Examples
Code Examples