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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:04:13+00:00 2026-06-06T00:04:13+00:00

edit/operacoes.php header(‘Content-Type: application/json’); include(‘../../lib/mysql.class.php’); $db = new MySQL(); if($db->Error()) $db->Kill(); //VARIÁVEIS DA FORM $id

  • 0

edit/operacoes.php

header('Content-Type: application/json');
include('../../lib/mysql.class.php');

$db = new MySQL();
if($db->Error()) $db->Kill();

//VARIÁVEIS DA FORM
$id = intval($_POST['id']);

$sql = "SELECT * FROM operacoes WHERE id=$id";
if(!$db->Query($sql)) $db->Kill();

$db->MoveFirst();
$row = $db->Row();
$data['nome'] = $row->nome;
$data['produto'] = $row->produto;
$data['componente'] = $row->componente;
$data['materiaprima'] = $row->materiaprima;

echo json_encode($data);

jQuery:

$.post('edit/operacoes.php',{id:id},function(data){
    $('div.form-container h1.title').text("Editar Existente");
    $('input#idbd').empty().val(id);
    $('input#nome').empty().val(data.nome);
    $('input#produto').attr('checked', (data.produto==1)?true:false);
    $('input#componente').attr('checked', (data.componente==1)?true:false);
    $('input#materiaprima').attr('checked', (data.materiaprima==1)?true:false);
    $('div#addbuttons').css('display','none');
    $('div#editbuttons').css('display','block');
    showPopup();
});

HTML:

<tr>
    <td colspan="3" class="input listas">
        <select multiple="multiple" name="escolha_ferramentas" id="escolha_ferramentas" size="15" class="list">
            <option value="3">Ferramenta 3</option>
            <option value="4">Ferramenta 4</option>
            <option value="5">Ferramenta 5</option>
            <option value="6">Ferramenta 6</option>
        </select>
        <div class="list-controls">
            <input type="button" value=">" id="next-ferramentas"><br><br>
            <input type="button" value="<" id="prev-ferramentas">
        </div>
        <select multiple="multiple" name="ferramentas[]" id="ferramentas" size="15" class="list">
        </select>
        <div style="clear:both;"></div>
    </td>
</tr>

This works great, except for the selects.

The logic is, the ids that are in the BD (a different one), are the options that need to be in the right select and removed from the left select (append to the right select and remove from the left select).

My question is, how, using json, can I achieve this? Get the ids to the jquery and then loop them to move the options from one select to another?

Edit
I created another php file just to give the ids I need. PHP returns ["2","3","4"]. How do I loop through that in jQuery.post function(data){loophere}

  • 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-06T00:04:14+00:00Added an answer on June 6, 2026 at 12:04 am

    I would pass an array of strings from the PHP (the json looks like ['string','string','string'] and then use a loop on that to indicate what ones to put “on the other side”.

    I don’t see where you’re returning those from the server yet, so maybe the language translation on the passed elements is throwing me off, but it’s evident that you’re making one of these:

        A           B
    [       ]   [       ]
    [       ] > [       ]
    [       ] < [       ]
    [       ]   [       ]
    

    Just pass the elements that need to be removed from A into B as a string array, and loop over the array elements.

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

Sidebar

Related Questions

I've been writing a complex numbers header from scratch for a school class but
I have created a class of type Base36, and am coding the type conversion
Edit: I posted the whole class (striped a few for the error irrelevant things
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
EDIT: Now a Major Motion Blog Post at http://messymatters.com/sealedbids The idea of rot13 is
EDIT: I used, finally, inotify. As stefanB says, inotify is the thing to use.
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
EDIT: OK, I believe the following solutions are valid: Use the jQuery AOP plugin.
EDIT 2 Okay, based on the advice on the answers below I eliminated my
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm

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.