hazel Posted June 13, 2006 Share Posted June 13, 2006 Hi everyone,I have a question again.... now i want to display the sub data under a header title, hmm i dont really know how to explain that in words. the example should show it clearly:Title: sub title1 sub title2 sub title3 sub title4 ...Title1: sub title1 sub title2 ...Title2: ...and so on... All the title are under main item. How do i extract the datas all from 1 table?? and arrange them like above as shown. Link to comment Share on other sites More sharing options...
DarkElf Posted June 13, 2006 Share Posted June 13, 2006 You need to store the titles in an array, and then have a subarray under each title storing the subtitles. You can then use nested foreach loops to work through the main array and then each subarray to list the contents. Link to comment Share on other sites More sharing options...
hazel Posted June 14, 2006 Author Share Posted June 14, 2006 Hi darkelfyour solution sound logic to me. but how do i extract the titles and subtitles out from a table from a table? well, heres another example, i have productID, versionID and software column in a table. Under productID theres different versionID and under A versionID there would be different software. What i want to do now is to extract those versionID and software that belongs to 1 productID. And list the software under its own versionID. hm, some example code would be better Link to comment Share on other sites More sharing options...
Jack McKalling Posted June 15, 2006 Share Posted June 15, 2006 (edited) These both example need nested loops, and it actually doesn't matter what loop anyway Just what you prefer. Example code: $titles = array( "Title1" => array('subtitle1.1','subtitle1.2','subtitle1.3','subtitle1.4'), "Title2" => array('subtitle2.1','subtitle2.2','subtitle2.3','subtitle2.4'), "Title3" => array('subtitle3.1','subtitle3.2','subtitle3.3','subtitle3.4'));foreach ($titles as $titlename => $subtitles){ echo "<h3>$titlename</h3>"; foreach ($subtitles as $subtitlename) { echo "\r\n<h4>$subtitlename</h4>"; } echo "<br />\r\n";}And this would result in: Title1subtitle1.1subtitle1.2subtitle1.3subtitle1.4Title2subtitle2.1subtitle2.2subtitle2.3subtitle2.4Title3subtitle3.1subtitle3.2subtitle3.3subtitle3.4Well, at least the bold titles would be larger than the subtitles, but I don't like to post such large text here Edited June 15, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
hazel Posted June 17, 2006 Author Share Posted June 17, 2006 Thanks all, i managed to solve my problem!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now