Jump to content

Displaying Values In Table


kirk112

Recommended Posts

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! ???
Link to comment
https://forums.phpfreaks.com/topic/24188-displaying-values-in-table/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.