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

  • Home
  • SEARCH
  • 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 6630619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:25:52+00:00 2026-05-25T22:25:52+00:00

I have assigned two array to smarty : profiles and selected_id . profiles array

  • 0

I have assigned two array to smarty : profiles and selected_id . profiles array contains the array of all profiles and the selected_id array contains ids of the profiles to be displayed .So I am displaying the all profiles like this :

<select id="countries" class="multiselect" multiple="multiple" name="profiles[]">
        {foreach name = feach item = k from = $profiles}
            <option value="{$k->bz_pro_id}">{$k->bz_pro_first_name} {$k->bz_pro_last_name}</option>
        {/foreach}
      </select>

Now I want to default select the ids that are already selected by admin . That means if I want to add selected = "selected" in the option of select . For that I write :

{foreach name = feach item = k from = $profiles}
        {foreach name = feach2 item = k2 from = $selected_id}
                {if $k->bz_pro_id == $k2->bz_pro_id}
                        selected = "selected"
                {/if}
        {/foreach}
{/foreach}

So can I assign the select = "selected" to a variable so that I can use it in the option ?

  • 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-05-25T22:25:53+00:00Added an answer on May 25, 2026 at 10:25 pm

    I have tested this, and it works. Assuming your arrays look something like this:

    $profiles[] = array ( 'bz_pro_id' => '1', 'bz_pro_first_name' => 'test1', 'bz_pro_last_name' => 'test2');
    $profiles[] = array ( 'bz_pro_id' => '2', 'bz_pro_first_name' => 'test3', 'bz_pro_last_name' => 'test4');
    $selected_id = array('1');
    

    The syntax you’re using to access variables and array members isn’t correct. This is the working solution:

    <select id="countries" class="multiselect" multiple="multiple" name="profiles[]">
        {foreach name=feach item=k from=$profiles}
            <option value="{$k.bz_pro_id}" 
               {if in_array($k.bz_pro_id, $selected_id)}selected{/if}>
                {$k.bz_pro_first_name} {$k.bz_pro_last_name}
            </option>
        {/foreach}
      </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In PHP, I have an associative array like this $a = array('who' => 'one',
I have two DIV-elements, which are assigned an array called stack using data() .
We have two tables - Tasks and TasksUsers (users assigned to task). Task has
Hey guys I have an assigned array from mysql results and I simply want
I have an array with the ids of x cakes and another associative array
I have two radio buttons, to which I have assigned change handlers to show/hide
First of all, this question is in regards to PHP and MySQL I have
I have been assigned to build a mobile web application. I have found two
I have two select lists that each display users and two buttons (add and
I have a record that contains a dynamic array. It is normal that when

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.