Page 1 of 1

PHP Smarty HTML columns

Posted: Wed Mar 03, 2010 1:04 pm
by VarwigDude
Hello all,

I cannot find a example to where if i have products in a mysql table and i want to use 3 columns to display the products. Then After the first 3 products are displayed then there is a new row. Anyone know a simple way to do this with smarty and PHP?

Thanks Everyone

Re: PHP Smarty HTML columns

Posted: Wed Mar 03, 2010 4:17 pm
by lshaw
Smarty is a template engine? anyway my code for this would be:

Code: Select all

 
$count=0; //set a variable to count rows
//start the while loop of mysql_fetch_array()
{
//echo what you want
$count++;//increase count
if($count==3)
{
echo "<br />"; //start a new line
$count=0;
}
}//end the while loop
 
 
 

Re: PHP Smarty HTML columns

Posted: Wed Mar 03, 2010 4:26 pm
by AbraCadaver
Actually you would want:

Code: Select all

if($count % 3 == 0)
And you can do this in smarty with:

Code: Select all

{if $count is div by 3}
//or
{if $count mod 3 == 0}
//or
{if $count % 3 == 0}