Page 1 of 1

Set number of columns in a table

Posted: Tue May 11, 2010 10:23 am
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 118 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 !

Re: Set number of columns in a table

Posted: Tue May 11, 2010 5:18 pm
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.

Re: Set number of columns in a table

Posted: Wed May 12, 2010 3:34 am
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/