Forum Moderators: coopster

Message Too Old, No Replies

Output table format

         

sfast

10:17 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



I need to retrieve the data from the MySQL table using PHP.

Normally I would have -

while loop
echo <tr>
...
echo </tr>

Output
1
2
3
4
5
.
.
.
_______________

But I want it in below format -
1 2
3 4
5 6
7 8
. .
. .
. .

Can somebody guide me how can I achieve this?

coopster

2:17 am on Jul 4, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Our PHP Forum Library [webmasterworld.com] has a lot of useful tips and tricks, including one to create rows and columns as you mention here.

Good PHP solutions to small problems [webmasterworld.com]
The 4th tip down describes how to Create a Dynamic Table from mysql result

vincevincevince

2:42 am on Jul 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of a table, use <div> elements inside one outer div (class 'grid') and apply this CSS:
<style>
.grid div {width:49.5%;float:left;display:block;}
</style>

The HTML should be just:

<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</grid>

You will get the result you need from that.

If you wanted to change to three columns:

.grid div {width:32.5%;float:left;display:block;}

Or to four columns:

.grid div {width:24.6%;float:left;display:block;}