Set number of columns in a table

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
blink41
Forum Newbie
Posts: 4
Joined: Mon May 10, 2010 10:14 am

Set number of columns in a table

Post by blink41 »

Hey all !
So I've made some progress in my project, but there's a problem I don't know how to solve :
I've attached a picture showing the result (
screenshot
screenshot
columns.JPG (48.77 KiB) Viewed 119 times
). What I'd like to have is a table where each product has its column. I think I should use foreach, but I didn't find examples corresponding to what I want. Here's my code :

Code: Select all

<table id='tabletest' width='100%' class='sample'>

	<?php

		while($row = mysql_fetch_array($result))
		{
?>
<tr>
<td align='center'><img src='/abcm/image.php/<?php echo $row['fichier'] ?>?width=150&height=150&cropratio=1:1&image=/abcm/images/<?php echo $row['fichier'] ?>' alt='Dont forget your alt text' />test1</td>
<td align='center'><img src='/abcm/image.php/<?php echo $row['fichier'] ?>?width=150&height=150&cropratio=1:1&image=/abcm/images/<?php echo $row['fichier'] ?>' alt='Dont forget your alt text' />test2</td>
<td align='center'><img src='/abcm/image.php/<?php echo $row['fichier'] ?>?width=150&height=150&cropratio=1:1&image=/abcm/images/<?php echo $row['fichier'] ?>' alt='Dont forget your alt text' />test3</td>
</tr>


<?php
		}
	?>
</table>
I understand why there are 3 products per line, here's what I'd like :

Code: Select all

<table id='tabletest' width='100%' class='sample'>

	<?php

		while($row = mysql_fetch_array($result))
		{
?>
<tr>
<td align='center'><img src='/abcm/image.php/<?php echo $row['fichier - 1st line'] ?>?width=150&height=150&cropratio=1:1&image=/abcm/images/<?php echo $row['fichier'] ?>' alt='Dont forget your alt text' />test1</td>
<td align='center'><img src='/abcm/image.php/<?php echo $row['fichier - 2nd line'] ?>?width=150&height=150&cropratio=1:1&image=/abcm/images/<?php echo $row['fichier'] ?>' alt='Dont forget your alt text' />test2</td>
<td align='center'><img src='/abcm/image.php/<?php echo $row['fichier - 3rd line'] ?>?width=150&height=150&cropratio=1:1&image=/abcm/images/<?php echo $row['fichier'] ?>' alt='Dont forget your alt text' />test3</td>
</tr>


<?php
		}
	?>
</table>
Thanks for your answers !
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Set number of columns in a table

Post by cpetercarter »

A possibility would be three separate tables, one for each product. Each table would have only one item per row ie they would be long vertical tables. Then use css to float the three tables alongside each other.
blink41
Forum Newbie
Posts: 4
Joined: Mon May 10, 2010 10:14 am

Re: Set number of columns in a table

Post by blink41 »

Well, that seems interesting, but I'd rather edit the php code. Do you or someone else know where I could find examples of what I want ?

EDIT : Solved it, here is the example I used in case there are some people interested : http://www.codewalkers.com/c/a/Database ... QL-output/
Post Reply