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 7919345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:50:04+00:00 2026-06-03T15:50:04+00:00

I’ve got a list of records with edit links on them. When i click

  • 0

I’ve got a list of records with edit links on them. When i click on the link it takes me to an edit page with the results from the database.

I can retrieve the data successfully for all the text boxes.

I’m trying to implement this via an array which fails to work.

Here is my implementation in code fragments:

        # $data is from $data=mysqli_fetch_array($result)


                        $product=$data['product'];
                        echo $product.'<br />';

        #initializing array to empty
           $product_list=array("Remote"=>" ","TV"=>" ","Box"=>" ");

        if (array_key_exists($product,$product_list)){


            $product_list["'$product'"] =  'selected="selected" ';


            }

                            print_r($product_list);


        #combo box 

              <select name="products">
                        <option value="select">Select</option>
                        <option value="Remote"<?php echo @$product_list["'$product'"] ?>>Remote</option>
                        <option value="TV" <?php echo @$product_list["'$product'"] ?>> TV</option>
                        <option value="Box" <?php echo @$product_list["'$product'"] ?>> Box</option>
                    </select>

In the page that displays all the records if i hit edit on a record that has product ‘Remote’ i get the following output(as per echo statements above):

Remote
Array ( [Remote] => [TV] => [Box] => ['Remote'] => selected="selected" ) 

The HTML form displays:

 <select name="products">                   
    <option value="select">Select</option>
        <option selected="selected" value="Remote">Remote</option>
        <option selected="selected" value="TV"> TV</option>
        <option selected="selected" value="Box"> Box</option>
</select>

In the edit page if i select a record that has product ‘TV’ i get the following output:

 TV
 Array ( [Remote] => [TV] => [Box] => ['TV'] => selected="selected" ) 

HTML output is same as above. And it always sets the option to the last product which is ‘Box’.

Can somebody please advise on how i can fix this? thanks!

  • 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-03T15:50:06+00:00Added an answer on June 3, 2026 at 3:50 pm

    This:

    $product_list["'$product'"] =  'selected="selected" ';
    

    should be

    $product_list[$product] =  'selected="selected" ';
    

    And in other places that have $product_list["'$product'"] you should also remove quotes.

    Edit:

    Here

    <select name="products">
        <option value="select">Select</option>
        <option value="Remote"<?php echo @$product_list["'$product'"] ?>>Remote</option>
        <option value="TV" <?php echo @$product_list["'$product'"] ?>> TV</option>
        <option value="Box" <?php echo @$product_list["'$product'"] ?>> Box</option>
    </select>
    

    you are not using any loop and trying to get the value of $product_list[$product] in every item – $product will always be the same in every line and equal to the last one fetched from mysql.

    You have either to use correct index in each line (ie. <?php echo $product_list['TV']; ?>) or proper way – use the loop:

    <select name="products">
        <option value="select">Select</option>
        <?php foreach($product_list as $product_name => $selected): ?>
        <option value="<?= $product_name ?>" <?= $selected ?>><?= $product_name ?></option>
        <?php endforeach; ?>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.