How to Loop Through an Array in Clip-Bucket with {section}{/section}


When you dynamically need to output records from a database inside your Clip-Bucket, by this moment, you may have noticed that Clip-Bucket is powered by Smarty template engine, therefore, you cannot use a while() loop, for example, like you would normally do in native PHP. In this article we will review the use of {section}{/section} to loop through a MySQL records array.

Difficulty level: Medium (if you know how to use loops in PHP, you’ll find it easier)

1. Create the query to retrieve records from your database (in this example I’ll use queries for MySQL, but you can use any database)

$q = "SELECT * FROM yourtable";

2. Assign the result to the template with Clip-Bucket’s $db->getAll();


3. Now in your HTML file, we are going to loop through the results of $ourarray

Let’s imagine our table: yourtable, has the following:

| id |  name | views |
| 1  | you   |  123  |
| 2  | other |  1    |
| 5  | rob   |  1    |

4. We want to display: NAME has VIEWS views for every name

{section name=myloop loop=$ourarray}
{$ourarray[myloop].name} has {$ourarray[myloop].views} <br>

The output for that code would be:

you has 123 views
other has 1 views
rob has 1 views

5. So we now know that the correct use to display an element from the array using section, is to use $previouslyassignedarray[nameofoursection].element ({section name=nameofoursection loop=$previouslyassignedarray}{/section})

Remember to close the section with {/section}. If you want to learn more about the other parameters that this loop can use, please refer to: . Any questions you may have with these, let me know and I’ll be more than glad to assist you.

Best Regards,


Owner of Juapo2Services

Looking for quality ClipBucket hosting? Try out Arvixe and you won’t be disappointed.
Tags: , , , , , , , , , , | Posted under ClipBucket | RSS 2.0

Author Spotlight

Richi González

I started programming when I was 12. I'm a Developer and have been working with the Clip-Bucket script since it came out. I'm the Liaison between Arvixe and Clip-Bucket, so anything you need regarding Clip-Bucket or any particular computer-related subject you need, let me know so I can assist you.

Leave a Reply

Your email address will not be published. Required fields are marked *