ozestretch Posted July 3, 2013 Share Posted July 3, 2013 I am creating a dynamic human readable sitemap from mysql>php. the array is created with; (array structure can be altered if this is causing the grief) <?php $row['category'] = varchar; // list of 10 categories $row['status'] = int; // 0,1 or 2 $row['id'] = int; // 1,2,3,4... (AI) // set the title for link $this->sitemap[$row['category']][$row['status']]['title'][$row['id']] = $row['seo_title']; // set the url for link $this->sitemap[$row['category']][$row['status']]['url'][$row['id']] = $row['slug'].".php"; ?> My required output to be as; <ul> <li>category[0] <ul> // all category[0][2] <li><a href="category[0][2]['title']['the row id']">category[0][2]['title']['the row id']</a></li> etc... // all category[0][1] <ul> <li><a href="category[0][1]['title']['the row id']">category[0][1]['title']['the row id']</a></li> etc.... // all category[0][0] <ul> <li><a href="category[0][0]['title']['the row id']">category[0][0]['title']['the row id']</a></li> </ul> </ul> <li>category[1] <ul> // all category[1][2] <li><a href="category[1][2]['title']['the row id']">category[1][2]['title']['the row id']</a></li> etc... keep in mind where caetgory[0] is a string as key, not an integer. Any ideas or questions welcomed, thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted July 3, 2013 Share Posted July 3, 2013 Two questions: Where is your code? Where exactly are you stuck? Quote Link to comment Share on other sites More sharing options...
Solution ozestretch Posted July 4, 2013 Author Solution Share Posted July 4, 2013 Thanks trq, made me revisit the way I was thinking. I got it to output as desired, but am wondering if it is efficient.. thoughts? <?php $output = new GetSitemap('html'); $sitemapout = ""; foreach($output->sitemap as $categorykey => $value){ $sitemapout.= " <li><strong>".ucwords($categorykey)."</strong> <ul class='first'>\n"; // loop first level pages - status = 2 foreach($output->sitemap[$categorykey][2]['title'] as $cat2key => $cat2value){ $sitemapout.= " <li><a href='{$output->sitemap[$categorykey][2]['url'][$cat2key]}'>{$cat2value}</a></li>\n"; } // loop second level pages - status = 1 $l2 = 0; foreach($output->sitemap[$categorykey][1]['title'] as $cat3key => $cat3value){ if($l2==0){ $sitemapout.= " <ul class='second'>\n"; } $sitemapout.= " <li><a href='{$output->sitemap[$categorykey][1]['url'][$cat3key]}'>{$cat3value}</a></li>\n"; $l2++; } if($l2>0){ $sitemapout.= " </ul><!--// second //-->\n"; } // loop third level pages - status = 0 $l3 = 0; foreach($output->sitemap[$categorykey][0]['title'] as $cat4key => $cat4value){ if($l3==0){ $sitemapout.= " <ul class='third'>\n"; } $sitemapout.= " <li><a href='{$output->sitemap[$categorykey][0]['url'][$cat4key]}'>{$cat4value}</a></li>\n"; $l3++; } if($l3>0){ $sitemapout.= " </ul><!--// third //-->\n"; } $sitemapout.= " </ul><!--// first //-->\n </li>\n"; // end loop } echo "<ul>"; echo $sitemapout; echo "</ul>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.