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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:32:32+00:00 2026-06-11T17:32:32+00:00

I have a list of optional clothing items as checkboxes, there may be a

  • 0

I have a list of optional clothing items as checkboxes, there may be a greater number than the 5 below.

shoes, pants, skirt, socks, jacket //list of possible choices

A comma-separated array is created in jquery of the chosen item. Let’s say the following are chosen:

shoes, socks, jacket //array posted as $_POST['clothes']

In the db, each customer has these options in the clothes table with ‘yes’ or ‘no’ under the clothing items. However, the clothing item are named a bit differently but map out to the same options:

‘clothes’ table before insert

customer_id  dress_shoes  elegant_pants  long_skirt  ankle_socks  biker_jacket
     1            no            yes           no           no           no

With the $_POST[‘clothes’], I’m trying to loop through the array, updating the corresponding fields to yes, and the non corresponding fields to no in the db. I’m having a hard time doing that.

‘clothes’ table after insert

customer_id  dress_shoes  elegant_pants  long_skirt  ankle_socks  biker_jacket
     1            yes            no           no          yes          yes

I tried using array_intersect() to get the items to mark as ‘yes’:

$clothesArray = array("shoes", "socks", "jacket"); // Posted clothes
$clothesArrayAll = array("shoes", "pants", "skirt", "socks", "jacket"); // All clothes
$common = array_intersect($clothesArrayAll,$clothesArray);
print_r($common);
Array ( [0] => shoes [3] => socks [4] => jacket )

I’m trying to somehow loop through the $clothesArrayAll, give a ‘yes’ to common clothes, and a ‘no’ to all others in the array. Then, I’m trying to update the ‘clothes’ table via PDO, setting each corresponding field to a ‘yes’ or ‘no’ in the most efficient way. I’m stuck after getting the common clothes array above and not sure how to proceed.

  • 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-11T17:32:33+00:00Added an answer on June 11, 2026 at 5:32 pm

    I think you are on the right track. I would just add one additional array that contains the mappings of your fields, e.g.

    $mappingArray = array('shoes' => 'dress_shoes', 'socks' => 'ankle_socks', ...);
    

    With this array and the previous you can loop through and set your SQL accordingly based on the value of the $common field with the key in the $mappingArray

    Edit with example (probably not the most optimized):

    $finalArray = array();
    
    foreach ($mappingArray as $key => $value) {
       $finalArray[$value] = in_array($key, $common) ? 'yes' : 'no';
    }
    

    $finalArray will now have an yes/no statement for each value that matches your db table.

    Edit to include PDO: I would actually update the above loop as follows:

    $finalArray = array();
    $sql = "INSERT INTO cloths (" . implode(",", array_values($mappingArray)) . ") VALUES (:" . implode(",:", array_values($mappingArray)) . ")";;
    foreach ($mappingArray as $key => $value) {
        $finalArray[":" . $value] = in_array($key, $common) ? 'yes' : 'no';
    }
    
    $q = $conn->prepare($sql);
    $q->execute($finalArray);
    

    Going on the fly with this one, so something like that…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have list of images and on mouse over there is option box shows
I have List with n items. I wish transform my list to new list,
I have a python option parsers that parses an optional --list-something option. I also
I'm making a Restful service in Which I have a list of items, which
I have a JSON Parser class that sends an Httppost if there is optional
I'm using Sinatra and Ruby 1.9.3. I have a list of items and want
I have a method with a lengthy list of optional arguments, such as: def
In Scala I have a List with an optional Option . This arises for
I have got four routes defined like this: //Project list with page number routes.MapRoute(
I have a script with a long list of OPTIONAL arguments. some have associated

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.