PHP Smarty HTML 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
VarwigDude
Forum Newbie
Posts: 12
Joined: Tue Mar 31, 2009 8:08 pm

PHP Smarty HTML columns

Post 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
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Re: PHP Smarty HTML columns

Post 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
 
 
 
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Smarty HTML columns

Post 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}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply