Page 1 of 1

Creating Columns

Posted: Thu Oct 23, 2003 1:24 pm
by brewmiser
Does anyone have a way of creating columns from a mysql query. In other words, I have a hole lot of names that I need to display in 3 columns on one web page. How do I go about doing this?

Thanks in advance for any help.

Posted: Thu Oct 23, 2003 1:46 pm
by McGruff
If I understand you rightly, this is a question about presentation.

An html table would fit the bill: create a new table row for each row in the db result resource and echo out col values in the table cells.

Posted: Thu Oct 23, 2003 1:56 pm
by brewmiser
I am not for sure....I was thinking that you had to display a certain amount of names in each column with a php script. So if I have a result of 30 names, and I want 10 names in each column.....

I do not think that this can be done in just plain html. I would need php to place 1-10 in $column1, 11-20 in $column2 and 21-30 in $column3.

Does this make anymore sense?

Posted: Fri Oct 24, 2003 3:23 am
by twigletmac
You need to count the results coming out and for every third one close the row and start a new one. As a starter try this code:

Code: Select all

for ($i = 1; $i <= 30; $i++) {
	echo $i.' - ';
	echo (($i%3) == 0) ? '<b>Third Result</b>' : '';
	echo '<br />';
}
Mac

Posted: Fri Oct 24, 2003 8:00 am
by brewmiser
Thanks twigletmac, I will give it a try.