Jumpy09 Posted May 18, 2010 Share Posted May 18, 2010 Is there anyway of taking: $database; $q =" SELECT m.maincatname,m.maincatinfo,s1.subcat1name,s1.subcat1info,s2.subcat2name,s2.subcat2info,i.itemname,i.iteminfo,i.datestarted,i.datecompleted,i.ilevel FROM progression_maincat m, progression_subcat1 s1, progression_subcat2 s2, progression_iteminfo i WHERE s1.maincatid = m.maincatid AND s2.subcat1id = s1.subcat1id AND i.subcat2id = s2.subcat2id GROUP BY i.itemid ORDER BY i.itemid ASC"; $result = mysql_query($q) or die(mysql_error()); error_reporting (E_ALL); echo '<table width="100%" align="left">'; while ($row = @mysql_fetch_array($result)) { $mcname =$row['maincatname']; $mcinfo =$row['maincatinfo']; $sc1name =$row['subcat1name']; $sc1info =$row['subcat1info']; $sc2name =$row['subcat2name']; $sc2info =$row['subcat2info']; $itemname =$row['itemname']; $iteminfo =$row['iteminfo']; $datestarted =$row['datestarted']; $datecompleted =$row['datecompleted']; $ilevel =$row['ilevel']; echo "<tr align=\"left\"><td width=\"30%\">Main Category: $mcname</td><td width=\"45%\">Main Category Info: $mcinfo</td><td></td><td></td></tr>"; echo "<tr align=\"left\"><td colspan=\"\">      Seconday Category: $sc1name</td><td>Secondary Info: $sc1info</td></td><td></td><td></td></tr>"; echo "<tr align=\"left\"><td>            Sub-Category Name: $sc2name</td><td>Sub-Category Info: $sc2info</td></td><td></td><td></td></tr>"; echo "<tr align=\"left\"><td>                  $itemname</td><td>$iteminfo</td><td>$datestarted-$datecompleted</td><td>$ilevel</td></tr>"; } echo "</table>"; and turn it into something like: +Main Category +Secondary Category + Sub-Category + Item + Item + Sub-Category +Secondary Category + Sub-Category + Item + Item + Sub-Category +Main Category +Main Category The query loads everything right, but I can't figure out how to design the php code to make it render right. Right now it loads like: +Main Category +Secondary Category + Sub-Category + Item +Main Category +Secondary Category + Sub-Category + Item +Main Category +Secondary Category + Sub-Category + Item Which is not only a problem but annoying as hell. Any suggestions? Thanks in advance, much appreciated. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted May 18, 2010 Share Posted May 18, 2010 Try that http://www.hawkee.com/snippet/1800/ If that doesn't do it, take a look at some other google results http://www.google.com/search?q=category+tree+php+mysql+recursive Quote Link to comment Share on other sites More sharing options...
Jumpy09 Posted May 18, 2010 Author Share Posted May 18, 2010 Tree! Thanks, that's the word I've been looking for. Thanks for the links, much appreciated. Quote Link to comment Share on other sites More sharing options...
katierosy Posted May 19, 2010 Share Posted May 19, 2010 This link may help http://www.hawkee.com/snippet/1800/ Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted May 19, 2010 Share Posted May 19, 2010 @katierosy - I did post that link in my first post 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.