Jump to content


Photo

Displaying Values In Table


  • Please log in to reply
3 replies to this topic

#1 kirk112

kirk112
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts
  • LocationEngland

Posted 17 October 2006 - 09:49 AM

I have a query that selects:

id initals value
1  sk    13
2  sk    15
3  ge    13
4  hy    13
6  me    16
7  sk    14
8  hy    15

What I need to do is display the information in the following format, for the life of me I can not work how

SK  GE  HY  ME
13  13  13  16
13        15
13
13

52  13  18  16  Total

Thank you for your time.  Totally stumped! ???

#2 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 17 October 2006 - 09:53 AM

This sort of resembles an issue that I am having with my arrays...  I am working on figuring it out and when I do I'll post something here to help you -- unless someone does before hand...

#3 kirk112

kirk112
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts
  • LocationEngland

Posted 20 October 2006 - 07:31 AM

Radar

Just wondering if you manage to work out how to achieve this?  Been trying for the last couple of days and can't find a way of getting it to work properly.

Cheers




#4 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 20 October 2006 - 08:01 AM

Looks like a course exercise to me :)  I think that any way to do it will be messy.

I would do it like this:

1. Rearrange the data into an array using initials as the index, like:

array( 'sk' => array(13, 15, 14), 'ge' => 13);

2. Print out the header ("SK GE HY ME");

3. Print out the values, using an index variable to step through.  Ie, for ($i = 0; $i < $num_values; $i++) { print values in index $i for each initial }

That algorithm will work.  It's not elegant, but I can't think of any elegant way.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users