mjn Posted May 10, 2007 Share Posted May 10, 2007 Hi - I am getting 43000 results with this function. All I want are the parent categories. (parent = 0) I do not want the children listed in this list - that makes it ridonculous. BUT - I've tried to put parent = 0 in the places where I think they would go - no dice. I have only limited skills and this is a big joomla component - and the joomla component people are being no help. All I need this function to do is show the parent categories. It also shows ROOT in the list the way it is - what a pain in the arse! Here be the code- Beers all around for any help! function buildcatList($cids, $where=""){ global $database; if ($where=="") { $database->setQuery( "SELECT *" . "\nFROM #__dir_cat ORDER BY name ASC" ); }else { $database->setQuery( "SELECT *" . "\nFROM #__dir_cat" . "\nWHERE $where ORDER BY name ASC" ); } $rows = $database->loadObjectList(); // establish the hierarchy of the menu $children = array(); // first pass - collect children foreach ($rows as $v ) { $pt = $v->parent; $list = @$children[$pt] ? $children[$pt] : array(); array_push( $list, $v ); $children[$pt] = $list; } $list = pxtTreeRecurse( 0, ' ', array(), $children, 9999 ); $options[] = mosHTML::makeOption('ROOT', '0'); foreach ($list as $item){ $options[] = mosHTML::makeOption($item->treename, $item->id); } if ($cids){ $lookup = pxt_convertCIDStoArray($cids); }else { $lookup[] = mosHTML::makeOption("ROOT","0"); } // mosHTML::multipleselectList($options,'cid','','text','value',$cids); return mosHTML::selectList( $options, 'cid[]', 'class="inputbox" size="10" multiple="multiple"', 'text', 'value', $lookup ); } Link to comment https://forums.phpfreaks.com/topic/50751-help-with-a-function-need-to-limit-returns/ Share on other sites More sharing options...
siwelis Posted May 10, 2007 Share Posted May 10, 2007 Here's one solution ----------------------------------------------------- if ($where=="") { $database->setQuery( "SELECT *" . "\nFROM #__dir_cat ORDER BY name ASC LIMIT 20" //WHERE 20 IS HOW MANY RESULTS YOU WANT TO HAVE ); }else { $database->setQuery( "SELECT *" . "\nFROM #__dir_cat" . "\nWHERE $where ORDER BY name ASC LIMIT 20" //WHERE 20 IS HOW MANY RESULTS YOU WANT TO HAVE ); } ----------------------------------------------------- You might want to look into some pagination, in case you want those. http://php.about.com/od/phpwithmysql/ss/php_pagination.htm I'm a newbie still, so I'm only referring to seemingly well written articles until I trust my own advice! Dave Link to comment https://forums.phpfreaks.com/topic/50751-help-with-a-function-need-to-limit-returns/#findComment-249499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.