• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

QUESTION Parameters

jnf

New member
Messages
4
Likes
0
Points
1
#1
I use code to get an array of prices for my products from the database in a snippet called "Prices". In the page are old code like this:
Code:
[insert_php]echo $prices[nnn];[/insert_php]
where nnn is a product id ([11], [13], etc. - see example below).
How do I create a snippet so I can pass the 'nnn' to a single reusable snippet with a parameter for 'nnn'.
So I have an array of prices indexed by product id:
EG:
Code:
Array
(
    [11] => 9
    [13] => 7
    [16] => 12
)
Please see https://mountainsangha.org/products-on-sale. Note that there are no prices.
Thanks for your help.
 

Temyk

Developer & Support
Messages
1,129
Likes
42
Points
48
#2
Hello.

You can pass the product IDs separated by commas:
nnn='1,2,3,4,5'. And in the snippet code, convert this attribute to an array of PHP: explode - Manual
 

jnf

New member
Messages
4
Likes
0
Points
1
#3
Thanks. The problem was that the array of prices had to be global.
Thanks for your help.