like this:
Link
--Link
----Link
-----Link
now it can use onley 2 levels
i will use ul an li elements
________________________________
category index file
________________________________
<ul id="menileft">
<?php foreach( $tmpl->shopCat as $sf => $sd ) { $ii =
"sub-".$sd['scat_id'];?>
<li class='menileft-item'><a href="<?php e($tmpl->URL);
e($tmpl->shopCatPage);?>/<?php e($sd['scat_short']); ?>/" ><?php
e($sd['scat_name']); ?></a></li>
<?php if ( is_array( $sd['sub']) ) { ?>
<?php foreach( $sd['sub'] as $subr => $subd ) { ?>
<li class='menileft-item2'><a href="<?php e($tmpl->URL);
e($tmpl->shopCatPage);?>/<?php e($sd['scat_short']); ?>/<?php
e($subd['scat_short']); ?>/" ><?php e($subd['scat_name']); ?></a></li>
<?php } } ?>
<?php } ?>
</ul>
________________________________
category loader
________________________________
<?php
class frontCategoryLoader {
protected $module;
protected $page;
protected $table = 'x3_as_x3shop_cat';
public function __construct( $module, $page ) {
global $engine;
$this->module = $module;
$this->page = $page;
}
// Load
public function _loadCategories() {
global $engine;
$engine->db->Select( array( 'items' =>
'scat_id,scat_poredak',
'from' => $this->table,
'where' => array( 'scat_short' =>
$engine->url->action ),
'limit' => '1'
)
);
$id = $engine->db->Fetch( 'object' );
$sql_1 = array( 'items' => 'scat_id, scat_short, scat_name,
scat_parent, scat_poredak',
'from' => $this->table,
'where' => array( 'mod_id' =>
$this->module ,
'scat_parent' =>
$id->scat_id),
'order' => 'scat_poredak',
'limit' => '0, 1000'
) ;
$engine->db->Select( $sql_1 ) ;
while ( $rr = $engine->db->Fetch() ) {
$kj[$rr['scat_parent']][] = $rr;
}
$sql = array( 'items' => 'scat_id, scat_short, scat_name,
scat_parent, scat_poredak',
'from' => $this->table,
'where' => array( 'mod_id' =>
$this->module, 'scat_parent' => '0'),
'order' => 'scat_poredak',
'limit' => '0, 1000'
) ;
$engine->db->Select( $sql );
while( $r = $engine->db->Fetch() ) {
$kr[$r['scat_id']] = $r;
if ( is_array( $kj[ $r['scat_id'] ] )) {
$kr[$r['scat_id']]['sub'] = $kj[ $r['scat_id'] ];
}
/*if ( $r['scat_parent'] == 0 ) {
$kr[$r['scat_id']] = $r;
} else {
$kr[$r['scat_parent']]['sub'][] = $r;
} */
}
$engine->tmpl->shopCat = $kr;
$engine->tmpl->shopCatPage = $this->page;
}
}
?>
Hello,
It is hard to help you because you didn't provide a lot of information.
In general:
1) Make a recursive approach (That could also handle an arbitrary depth).
2) Expand your code so it looks in 2 deeper arrays too.
You are already scanning:
[level 0] $tmpl->shopCat as $sf => $sd
[level 1] $sd['sub'] as $subr => $subd
Now you can do the same thing on $subd.
But we can only guess what is inside that variable.
Here is a general tip: If you are wondering what is exactly inside a
variable, use print_r or vardump.
eg:
echo "What is in \$subd?<br><pre>";
print_r($subd);
echo "</pre>";
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
i know onley that category have
scat_id - ID of category
scat_name - name of categorry
scat_short - short link name
scat_parent = parent fo other category ID
"Erwin Moller"
<Since_humans_read_this...@spamyourself.com> wrote in
message news:4c68f58a$0$22903$e4fe...@news.xs4all.nl...
[Please don't toppost in comp.lang.php]
Hello,
Well, if you don't understand OO, and you don't know how the data is
*exactly* structured inside $tmpl->shopCat, how can anybody in
comp.lang.php help you?
Nobody in here has intimate knowledge of your application.
Unless you are using a very wellknown application (you didn't mention
which application you are using), chances are that nobody can help you
without further information.
I don't understand: why are you working on that application if you don't
know these things? In my humble opinion you should learn both (OO and
the exact structure of your data objects) before developing more,
because you will probably cause more damage than you solve like this.
If you are lucky somebody in here can see which application you are
using, and knows how to help you. (I know I cannot.)
Good luck!
Regards,
Erwin Moller