Re: array messing up

From: Date: Wed, 24 Nov 2004 08:48:39 +0000
Subject: Re: array messing up
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-37394@lists.php.net to get a copy of this message
Rainer Bendig Aka Ny wrote:
I want to build an array containing two arrays $navm[] and $navs[], $navs[] should go to $navm[items]. - -sourcecode:start--------------------8<------------------------------ $resultm = $db->query("SELECT * FROM ".$p."_cats WHERE ms='m' \
           ORDER BY sortorder ASC");
while($work_res_navm = $db->fetch_array($resultm)) {
      $results = $db->query("SELECT * FROM ".$p."_cats  \
                 WHERE master='".$work_res_navm['catid']."' \
ORDER BY sortorder ASC");
$navs = array();
                    while($work_res_navs = $db->fetch_array($results)) {
                     $navs[]=array('link'=>$work_res_navs['link'], \
		                   'text'=> $work_res_navs['name'], \
'id'=> $work_res_navs['catid'], \ 'master'=>$work_res_navs['master'] );
               }
      $navm[] =array('link'=>$work_res_navm['link'], \
                     'text'=> $work_res_navm['name'], \
		     'id'=> $work_res_navm['catid'], \
		     'items'=>$navs);
}; - -sourcecode:stop---------------------8<------------------------------ the array now looks like this: $navm1-0
     $navs1-1
     $navs1-2
$navm2-0
     $navs1-1
     $navs1-2
     $navs2-1
$navm3-0
     $navs1-1
     $navs1-2
     $navs2-1
     $navs3-1
and the same procedure a lot more often... but it should look like this: $navm1-0
     $navs1-1
     $navs1-2
$navm2-0
     $navs2-1
$navm3-0
     $navs3-1
and so on what is my error?
you forget to empty the array $navs! -- Sebastian Mendel www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com www.sf.net/projects/phpdatetime www.sf.net/projects/phptimesheet

« previous php.db (#37394) next »