Results 1 to 7 of 7

Thread: CGI, HTML and 'sprintf' function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Posts
    26
    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

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Why not use HTML tables?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Posts
    26
    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.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Posts
    26
    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.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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 .
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Posts
    26
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width