Hello everyone here,

I want to be able to read from file or DB and place lines on a page in Matrix form. This is what I mean, say I read a file to an array or list(of string), so that I have the lines like this
1.aaaa,bbbb,ccc
2.5533ds,iodfas,ssss

  1. 2211,bbb,eeee
  2. yyyy,hhhh,uuuu
  3. dddd,wwww,aaaa
  4. bbbb,xxxxx,uuuu
  5. nnnn,iiiiii,tttttt
  6. oooo,yyyyy,eeee
  7. pppp,sssss,tttttt

so puting them in matrix like 3x3, I want to have something like
aaaa,bbbb,ccc --- 5533ds,iodfas,ssss --- 2211,bbb,eeee
yyyy,hhhh,uuuu --- dddd,wwww,aaaa --- bbbb,xxxxx,uuuu
nnnn,iiiiii,tttttt --- oooo,yyyyy,eeee --- pppp,sssss,tttttt

Thank you.

And what have you already tried yourself?

I have not tried out anything at all. Its a little bit complex for me.

If it's too complex, break the problem apart into smaller steps. You have a goal and to get their you move towards it in steps.

1.aaaa,bbbb,ccc
2.5533ds,iodfas,ssss
3.2211,bbb,eeee
4.yyyy,hhhh,uuuu
5.dddd,wwww,aaaa
6.bbbb,xxxxx,uuuu
7.nnnn,iiiiii,tttttt
8.oooo,yyyyy,eeee
9.pppp,sssss,tttttt

I rewrote your list, hope I understand this: so you want item 1 to 3 , 4 to 6 and 7 to 9 in a list?
What would be wrong with a list of a list of string?
You could use indexing the first list to map the items to this second to be created list.

Here is my take...

First, you need to be able to read the data from a file or DB, and either store them in your program or display them right away. Assuming that you already know how to read data from file, so I will skip it.

Second, you need to think of the whole line as ONE item. Thus, you now have 9 items in 9 lines. Then, you imagine that you have a 3x3 shelf that you are going to fill it with your 9 items. Simply put each item in the slot one-by-one starting from the top row and go from left to right.

The description above is for a real life situation. Now you need to convert the idea into programming. Let's imagine a 2 dimensional display on monitor as below.

+-------+-------+-------+
| item1 | item2 | item3 |
+-------+-------+-------+
| item4 | item5 | item6 |
+-------+-------+-------+
| item7 | item8 | item9 |
+-------+-------+-------+

When you are displaying the table above, you should be able to break the grid down as...

+-------+-------+-------+

| item1 | item2 | item3 |

+-------+-------+-------+

| item4 | item5 | item6 |

+-------+-------+-------+

| item7 | item8 | item9 |

+-------+-------+-------+

There are many ways to display the grid. You could explicitely write out each line, but that is not a recommended way to do. What you should use in the display is a nested loop. So I hope you understand how a nested loop works.

Hope this help...

commented: Good explanation +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.