Jump to content

??should i use foreach function??


hazel

Recommended Posts

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

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

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.4
Well, at least the bold titles would be larger than the subtitles, but I don't like to post such large text here :) Edited by Dan The Prof
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...