|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Jackie Smarty n00b
Joined: 30 Dec 2010 Posts: 1
|
Posted: Thu Dec 30, 2010 10:26 pm Post subject: A alternative for the while() loop |
|
|
Hi,
I am going to show you how to create a while() loop in smarty.
The PDO example
First lets make connection to the MySQL database
Code: | $dbh = new PDO("mysql:host=xxx;dbname=xxx", "xxx", "xxx"); |
Make a query
Code: | $stmt = $dbh->query("SELECT * FROM table_name"); |
We set the results in an array()
Code: | $results = array(); |
The while loop
Code: | while($res = $stmt->fetch(PDO::FETCH_ASSOC))
{
$results[] = $res;
} |
And do this in your template file to show the reccords
Code: | {section name=example loop=$results}
{$results[example].itsworks}
{/section} |
I hope i helped you all.
Sorry for my bad English, i am dutch |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|