Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:17:30+00:00 2026-06-13T18:17:30+00:00

In PHP file I am running a loop and within it I am assigning

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:17:31+00:00Added an answer on June 13, 2026 at 6:17 pm

    Ok I am exhausted trying different solutions, so finally I am doing this to achieve my target.

    Instead of below code
    PHP

    $contributors = $contributorsSql['users'];
    $smarty->assign("contributors$pinId", $contributors);
    

    I made the smarty variable an array

    PHP

    $contributors[$pinId] = $contributorsSql['users'];
    $smarty->assign("contributors", $contributors);
    

    And in smarty I am calling it as

    SMARTY:

    {$contributed[$results[res].id]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a continuous PHP loop that executes another PHP file by using exec(php
I'm running the PHP code below from command line. The issue is, its memory
I have a problem running another file from php. I want my php params
I am getting following error while running index.php file on apache File does not
I am having a problem with running commands via cli doctrine-cli.php file. I am
Trying to get MAMP running with Dreamweaver. When I preview a php file inside
In one PHP file, I have this code: require_once $_SERVER['DOCUMENT_ROOT'] . '/custom/functions.php'; global $testVar;
I'm running this inside a loop in WordPress: <?php if ( term_exists('term'=> 'pdf')) {
Here's the XML file i'm working on: <list> <activity>swimming</activity> <activity>running</activity> <activity>soccer</activity> </list> The index.php,
When a long-running PHP file is executing, and the user cancels the page request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.