In PHP file I am running a loop and within it I am assigning a variable for smarty.
PHP CODE:
foreach($pindata as $Idx => $Val)
{
$pinId = $Val['id'];
$sql = mysql_query("select count(userID) as users from pinrest_supporters where pin_id = $pinId;");
$contributorsSql = mysql_fetch_assoc($sql);
$contributors = $contributorsSql['users'];
$smarty->assign("contributors$pinId", $contributors);
}
So the values assigned in smarty are contributors1038, contributors1039 and so onnn.
Now my problem is that I want to use these assigned variables in smarty dynamically.
In smarty template file if I write {$contributors1038} then I get a correct output as 9. But I want to use it dynamically. 1038 is the ID, and I have that in my template. If I try to concat the two different variables and expecting the result, I am failed 😛
I tried this:
{assign var='contri' value="contributors"|cat:$results[res].id}
But the above variable {$contri} gives me result as contributors1038
I want to make a new variable by joining two different variable, but this makes it as string. So can anyone help me?
Ok I am exhausted trying different solutions, so finally I am doing this to achieve my target.
Instead of below code
PHP
I made the smarty variable an array
PHP
And in smarty I am calling it as
SMARTY: