Jump to content

Help with a Function - Need to Limit Returns


mjn

Recommended Posts

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 );

 

 

}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.