Displaying table data column-wise in a while loop

前端 未结 4 1960
栀梦
栀梦 2021-01-15 15:28

I\'m attempting to retrieve all that data from a database, put it in a table (more than one table if necessary) and display them column-wise in lots of 4 split across multip

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 15:45

    There's not enough information here to say whether or not you should be using a table because you provided non-data.

    If we're writing a closet organization application, our data might come out of the database like this:

    John | Shoes | 3
    John | Pants | 10
    Sally | Shoes | 12
    Sally | Pants | 8
    Billy | Shoes | 4
    Billy | Pants | 9
    Kate | Shoes | 6
    Kate | Pants | 6
    

    But we want to display it like this:

    Member | Shoes | Pants
    John | 3 | 10
    Sally | 12 | 8
    Billy | 4 | 9
    Kate | 6 | 6
    

    We would write our loop something like this:

    The headers? Well, typically I would recommend looping twice and resetting the pointer, but I don't see the equivalent of mysql_data_seek or pg_result_seek for the interface you're using, so I can't help you any farther than this. Using output buffering on the first "row" of results combined with a collector variable gathering up all of the headers as an array can work without the need to reset the pointer.

    If you're just wanting to spit out the results in 4 columns because you think it looks prettier and not because it expresses tabular data, using CSS columns would be the better way to go.

提交回复
热议问题