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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:40:03+00:00 2026-06-18T00:40:03+00:00

What I want to achieve: Insert data into database table using chained select list

  • 0

What I want to achieve:

Insert data into database table using chained select list (the options values ​are ​taken from database table)

Requirement: for the first select list (“tip_cheltuiala”), the available options values must be only the ones that are not used in the rows already inserted (available options are: option 1, 2 and 3; I already inserted rows with option 1 and 3, and now only option 2 must be available)

1. the select list “tip_cheltuiala”:

echo '<select name="tip_cheltuiala'.$row_chelt['id_factura'].'" id="tip_cheltuiala'.$row_chelt['id_factura'].'" class="selectContentIncasare">'.$opt_mod_inchidere->TipCheltuiala().'</select>';

and the function for that select list:

class SelectListModInchidere{
public function TipCheltuiala(){
                    //looking for options that are  already in the table
        $stmt_chelt_inchisa = $this->conn->prepare('SELECT tip_cheltuiala FROM cheltuieli_mod_inchidere');
        $stmt_chelt_inchisa->execute(array());
        $results_chelt_inchisa = $stmt_chelt_inchisa->fetchAll();
        foreach($results_chelt_inchisa as $row_chelt_inchisa) {
            $chelt_inchisa[] = $row_chelt_inchisa['tip_cheltuiala'];
        }
        print_r($chelt_inchisa); // returns options 1 and 3

        for($i=0; $i < count($chelt_inchisa); $i++){    

            $stmt_tip_chelt = $this->conn->prepare('SELECT * FROM mi_categ_cheltuiala 
            WHERE tip_cheltuiala <> :chelt_inchisa');
            $stmt_tip_chelt->execute(array('chelt_inchisa' => $chelt_inchisa[$i]));
            $tip_cheltuiala = '<option value="0">selectati ...</option>';
            while($row_tip_chelt = $stmt_tip_chelt->fetch()) {
                $tip_cheltuiala .= '<option value="' . $row_tip_chelt['tip_cheltuiala'] . '">' . $row_tip_chelt['tip_cheltuiala'] . '</option>';
            }
            return $tip_cheltuiala;
        }
    }
}
$opt_mod_inchidere = new SelectListModInchidere();

There I have the first issue: the select list is populated with option 2 (that is correct) but also with option 3 – I can’t figure out why.

2. the select list “mod_inchidere”:
returns the option values according with the selected option in select list “tip_cheltuiala

echo '<select name="mod_inchidere'.$row_chelt['id_factura'].'" id="mod_inchidere'.$row_chelt['id_factura'].'" class="selectContentIncasare">
      <option value="0">selectati ...</option>
      </select>';

and the function for that select list (part of the same class as function TipCheltuiala):

public function ModInchidere(){
        $stmt_mod_inch = $this->conn->prepare('SELECT * FROM mi_mod_inchidere WHERE categorie_cheltuiala = :categorie_cheltuiala');
        $stmt_mod_inch->execute(array('categorie_cheltuiala' => $_POST['id_categ_cheltuiala']));
        $mod_inchidere = '<option value="0">selectati ...</option>'; 
        while($row_mod_inch = $stmt_mod_inch->fetch()) {
            $mod_inchidere .= '<option value="' . $row_mod_inch['mod_inchidere'] . '">' . $row_mod_inch['mod_inchidere'] . '</option>';
        }
        return $mod_inchidere;
    }

3. final step: according with the selected option in select list “mod_inchidere, I need to return a value (also stored in database) correlated with the options in select list “mod_inchidre”, and put that values in a input field, so the user can (if he wants) modify that value.

At that step I have no idea how to accomplish that.
I can put the value in another select list, but: the user can’t modify that value and is not the way to do it.

Please help me with that.

LE

table structures

mi_categ_cheltuiala -> | id | tip_cheltuiala | categorie_cheltuiala |

mi_mod_inchidere -> | id | categorie_cheltuiala | mod_inchidere |

cheltuieli_mod_inchidere (table where I need to insert the data) -> | id | tip_cheltuiala | categorie_cheltuiala | mod_inchidere | valoare |

to get the value that I need to put in the input field I need to interrogate the table “mi_categ_valoare” for the field “mod_inchidere”

mi_categ_valoare -> | id | mod_inchidere | valoare |

$_POST[‘id_categ_cheltuiala’] -> explanation:

through jQuery I fetch what is selected in this select list “tip_cheltuiala” and send the data to the method TipCheltuiala()

<script type="text/javascript">
$(document).ready(function(){
    $("select#mod_inchidere<?php echo $row_chelt['id_factura']; ?>").attr("disabled","disabled");
            $("select#tip_cheltuiala<?php echo $row_chelt['id_factura']; ?>").change(function(){
            $("select#mod_inchidere<?php echo $row_chelt['id_factura']; ?>").attr("disabled","disabled");
            $("select#mod_inchidere<?php echo $row_chelt['id_factura']; ?>").html("<option>asteptati ...</option>");
            var id_categ_cheltuiala = $("select#tip_cheltuiala<?php echo $row_chelt['id_factura']; ?> option:selected").attr('value');
            $.post("class/select_mod_inchidere.php", {id_categ_cheltuiala:id_categ_cheltuiala}, function(data){
            $("select#mod_inchidere<?php echo $row_chelt['id_factura']; ?>").removeAttr("disabled");
            $("select#mod_inchidere<?php echo $row_chelt['id_factura']; ?>").html(data);
        });
    }); 
</script>

and then I use a service file that will invoke the method TipCheltuiala()

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

    To be honest: Non-English naming conventions making me dizzy 🙂

    Issue: There I have the first issue: the select list is populated with option 2 (that is correct) but also with option 3 - I can't figure out why.

    use below single query to get missing tip_cheltuila:

    SELECT 
        tip_cheltuila
    FROM
        mi_categ_cheltuiala
    WHERE
        tip_cheltuila NOT IN (SELECT 
                tip_cheltuiala
            FROM
                cheltuieli_mod_inchidere);
    

    Need to study other issues…

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

Sidebar

Related Questions

I want to insert some data into a database using a http post request.
I want to insert some data in a table of database after the SessionFactory
INSERT INTO contacts_lists (contact_id, list_id) SELECT contact_id, 67544 FROM plain_contacts Here I want to
I want to insert some values to a table (item1) from a table (item2)
I imported data from MS-Access into a SQL database using the import/export wizard. Now,
I have several transactions to insert form data into oracle table. if (InsertQuarterly() ==
Using this I successfully able to use qooxdoo to retrive data from my database
I want to insert couple of hundred rows into a table that points to
I want to know if it's possible to select incremented integer from mysql table?
I was searching for a way to insert data into two database tables in

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.