SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    United Kingdom
    0 Post(s)
    0 Thread(s)

    Need to dynamically create HTML table to display resultset

    I have a resultset which has

    It contains all the players in a competition along with their team and the type of player they are. I need to dynamically create a table which can contain this information. Bearing in mind that there are no set number of players, but there are 4 player types and 4 teams.

    The HTML table that I want to put these people into is 5 rows x 5 columns

    Hopefully it's not too long for you but I just wanted to give you a full picture (below) of how the code looks. My mind is flaking a bit trying to work out how to create this table dynamically and would absolutely love some help. I can see it going down the road of some FOR loops?? Could someone suggest an approach to this please?

    HTML Code:
    <table width="100%" border="1" cellspacing="2" cellpadding="2">
        <th scope="col">&nbsp;</th>
        <th scope="col">Player_type A </th>
        <th scope="col">Player_type B </th>
        <th scope="col">Player_type C </th>
        <th scope="col">Player_type D </th>
        <td scope="row">Team 1 </td>
        <td>Robert Burns<br />
    		Lord Byron<br />
    		Anton Chekov<br />
    		Tristan Corbi&egrave;re</td>
        <td>Dooly Wood<br />
    		Kenneth Tubbs<br />
    		Darren Logan<br />
    		Monty Parth<br />
    		Des Dimona </td>
        <td>Stephen Crane<br />
    		Ren&eacute; Daumal<br />
    		Jean de Brunhoff<br />
    		Guy de Maupassant<br />
    		Fyodor Dostoevski</td>
        <td>Paul Laurence Dunbar<br />
    		Paul &Eacute;luard<br />
    		Ralph Waldo Emerson<br />
    		Maxim Gorky</td>
        <td scope="row">Team 2 </td>
        <td>John Reed<br />
    		Edmond Rostand<br />
    		Jean-Jacques Rousseau<br />
    		John Ruskin<br />
    		Albert Samain<br />
    		Friedrich Schiller</td>
        <td>Edgar Allan Poe<br />
    		Alexander Pope<br />
    		Llewelyn Powys<br />
    		Winthrop Mackworth Praed</td>
        <td>Somerset Maugham<br />
    		Moli&egrave;re<br />
    		Eugene O'Neill<br />
    		George Orwell<br />
    		Walker Percy</td>
        <td>Franz Kafka<br />
    		John Keats<br />
    		Charles Kingsley<br />
    		Sidney Lanier<br />
    		D. H. Lawrence<br />
    		Katherine Mansfield</td>
        <td scope="row">Team 3 </td>
        <td>Washington Irving<br />
    		Panait Istrati<br />
    		Helen Hunt Jackson<br />
    		Alfred Jarry<br />
    		Samuel Johnson</td>
        <td>Saima Harmaja<br />
    		Iulia Hasdeu<br />
    		Robert A. Heinlein<br />
    		Miguel Hern&aacute;ndez</td>
        <td>Percy Bysshe Shelley<br />
    		Juliusz Slowacki<br />
    		Tobias Smollett</td>
        <td>Francis Thompson<br />
    		Henry David Thoreau<br />
        <td scope="row">Team 4 </td>
        <td>Lesya Ukrainka<br />
    		Thomas Wolfe<br />
    		Ji Wolker<br />
    		Fredric Bartholdi<br />
    		Marie Bashkirtseff</td>
        <td>Aubrey Beardsley<br />
    		Harry Clarke<br />
    		Paul Gauguin<br />
    		Boris Kustodiev</td>
        <td>Amedeo Modigliani<br />
    		Elizabeth Siddal<br />
    		Andrei Ryabushkin</td>
        <td>Laurence Sterne<br />
    		Robert Louis Stevenson<br />
    		Alan Sillitoe<br />
    		Dylan Thomas</td>

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Philadephia, PA
    1 Post(s)
    0 Thread(s)
    Well, after 15 lines I stopped trying to write this for you. Suffice it to say, you can definitely do this, and I used a multidimensional array to store the data from iterating through the result set, then ran nested foreach loops to access the inner arrays.

    I got to trying to retrieve the players from the types (accessed as an array inside teams keyed on team name)... and realized I would've had to write an array_multisort to sort each array within the teams array by type to get the data out in the same order as the column headings...

    Good luck

  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    United Kingdom
    0 Post(s)
    0 Thread(s)
    i'm vaguely understanding the route that you're taking, but to be honest I'm failing to see it properly. I have been trying to create something, but it's just mush at the moment. Is there any chance of giving me some visual representation of the code to go on?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts