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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.