RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Report w/Cateories/subcategories

Join Date: May 2007
Posts: 7
Reputation: tlei is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tlei tlei is offline Offline
Newbie Poster

Re: Report w/Cateories/subcategories

  #3  
May 24th, 2007
Originally Posted by johny_d View Post
Try this:
  1. $query = "SELECT `order`.`order`,`order`.id as oid,genus.genus,genus.id as gid,species.species, species.id as sid FROM `order`, genus, species WHERE `order`.id =genus.order_id AND genus.id=species.genus_id";
  2. $rows = mysql_query ($query);
  3.  
  4. while ($v = mysql_fetch_assoc ($rows)) {
  5. $order[$v['oid']] = $v['order'];
  6. $genus[$v['oid']][$v['gid']] = $v['genus'];
  7. $species[$v['gid']][$v['sid']] = $v['species'];
  8. }
  9.  
  10. $result = "<ul>";
  11. foreach ($order as $ko => $vo) {
  12. $result .= "<li>".$vo."\r\n <ul>\r\n";
  13. foreach ($genus[$ko] as $kg => $vg) {
  14. $result .= " <li>".$vg."\r\n <ul>\r\n";
  15. foreach ($species[$kg] as $ks => $vs) {
  16. $result .= " <li>".$vs."</li>\r\n";
  17. }
  18. $result .= " </ul></li>\r\n";
  19. }
  20. $result .= " </ul></li>\r\n";
  21. }
  22. $result .= "</ul>\r\n";
  23.  
  24. echo $result;
It worked on my comp.


Thanks, johnny_d. When I applied your script to my db I couldn't make it work - I tried checking all the syntax and everything, but I get nothing. The tables and fields I'm actually using are:
process [tbl]
   id [pk]
   process

step [tbl]
   id [pk]
   step
   process_id

substep [tbl]
   id [pk]
   substep
   step_id
...and here is the code I used, following your model
$query = "SELECT process.process,process.id AS pid,
    step.step.step.id AS sid ,
    substep.substep,substep.id AS bid
        FROM process,step,substep 
        WHERE process.id =step.process_id 
        AND step.id=substep.step_id";
    
    $rows=mysql_query($query) or die(mysql_error());
    
    while($d=mysql_fetch_assoc($rows) {    
        $process[$d['pid']] = $d['process'];
        $step[$d['sid']] = $d['step'];
        $substep[$d['bid']] = $d['substep'];
    
        $result = "<ul>";
        
        foreach($process as $key_p => $val_p) {
            $result .= "<li>" . $val_p . "\r\n <ul>\r\n";
            
            foreach($step as $key_s => $val_s) {    
                $result .= "   <li>" . $val_s . "\r\n <ul>\r\n";
                
                foreach($substep as $key_b => $val_b) {
                    $result .= "      <li>" . $val_b . "\r\n <ul>\r\n";
                    }
                $result .= "     </ul></li>\r\n";
                }
            $result .= "  </ul></li>\r\n";
            }
        $result .= "</ul></li>\r\n";
        }
    echo $result;
I'm sorry to be a pain, but can you see what I'm doing wrong? Thanks again.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:21 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC