PDA

Click to See Complete Forum and Search --> : CGI, HTML and 'sprintf' function


Peter Brown
Sep 10th, 2000, 05:16 AM
I want to display data from arrays in neat rows and columns in a browser. Tables just keep getting messed up.
I used the 'sprintf' function to format the data padding with spaces as necessary.
$result = sprintf("%-25s,%-10s,%-15s,%-5s,%-20s,%-20s,%-10s\n", $fields[0], $fields[1], $fields[2], $fields[3], $fields[4], $fields[5]);
But HTML does not display more that 1 space.
How do I get the display I want?
I tried replacing the space with ' ' but without success.
Any help would be appreciated.

Peter Brown

parksie
Sep 10th, 2000, 05:35 AM
Why not use HTML tables?

Peter Brown
Sep 10th, 2000, 08:43 AM
I tried tables first. But the data is of variable length so all that happened is that the columns in different rows were in different places, a right mess! I was looking for something consistant.

parksie
Sep 10th, 2000, 09:08 AM
What do you mean, they were in different places? In HTML if you don't specify a size the column takes its width from the largest object (depending on sizes of other columns and maximum table width).

Peter Brown
Sep 10th, 2000, 12:08 PM
I did specify the column widths, but this did not solve the problem. I had thought that specifying the width would 'fix' the width but this does not happen. If you try to put more text in one column than would fit then the column expands to suit the text. So if you have varying amounts of text in corresponding columns in different rows the columns do not line up. This is what I am trying to get round.

parksie
Sep 10th, 2000, 02:07 PM
What do they not line up with? Are you using one table with lots of rows, or lots of tables? I am really confused here :(.

Peter Brown
Sep 13th, 2000, 01:20 PM
OPPS, problem solved. Yes HTML tables are the way.
What I intended was one table with lots of rows. What I coded was lots of tables with one row - BIG MISTAKE !! Put some wrong bits inside the loop.
I now have one table with lots of rows, just what I wanted.
Thanks for the trouble in replying.