Creating Columns

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Creating Columns

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

Thanks twigletmac, I will give it a try.
Post Reply