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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:39:21+00:00 2026-06-15T04:39:21+00:00

I do have a two drop downs called as source and campaign and these

  • 0

I do have a two drop downs called as source and campaign and these two drop down showing the data that are coming from the data base.i do have others input fields as well.my concern is that i want to save this data after filling it in the given input and selecting drop downs data it must be saved but after saving the data the drop downs must show the selection that i had selected while clicking on save button but it is showing default one.
my code is as follows:
This is for Source:

 $result= mysql_query("SELECT * FROM infosources where kunnr = '".$_SESSION["kunnr"]."' order by sort_order asc");
    $model["source"]=array();
    while($row = mysql_fetch_array($result)){
        array_push($model["source"],$row);

}

This is for campaign:

$result= mysql_query("SELECT * FROM s_campaigns WHERE kunnr ='".$_SESSION["kunnr"]."' and active = 'true' order by name asc");
$model["campaign"]=array();
while($row = mysql_fetch_array($result)){
    array_push($model["campaign"],$row);

}

and my dropdown is as follows:

<select name="srcid"> <?php foreach($model["source"] as &$obj){?>
                       <option  value=<?php echo $obj["srcid"];?>>    <?php echo $obj["srcname"];?> </option> 
                           <?php }?></select>

and the other drop down is

<select name="camp_id"> <?php foreach($model["campaign"] as &$obj){?>
                       <option <?php if($model["selected"]==$obj[""]){?>selected <?php }?>  value=<?php echo $obj["id"];?>>    <?php echo $obj["name"];?> </option> 
                           <?php }?></select>

please suggest me on this…

  • 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-15T04:39:21+00:00Added an answer on June 15, 2026 at 4:39 am

    this is a very simplivied example and is just working if you send the form to the same file … if you send the form to any other file or if you pass the $selectedCampId variable from the other file back to this html form

    <?php
    
    // fetch the database to get all possible campaings always... before form was saved and also afterwards
    $result= mysql_query("SELECT * FROM s_campaigns WHERE kunnr ='".$_SESSION["kunnr"]."' 
        and active = 'true' order by name asc");
    
    $model["campaign"]=array();
    while($row = mysql_fetch_array($result)){
       array_push($model["campaign"],$row);
    }
    
    // initiate $selectedCampId .... if the form is sent ... this variable will be filled with the campaign_id so that we know which option was selected... otherwise it wil remain empty..
    $selectedCampId= '';
    
    // if the save button was pushed, the form method is POST and the camp_id is not empty
    // save the value of the camp_id input field to the variable so that in the next step 
    // we know which one was selected
    if(!empty($_POST['camp_id'])){
        // validate the input and save the data to database
        // check which campaign id is selected and write it to variable
        $selectedCampId= $_POST['camp_id'];
    }
    
    ?>
    <?php // the form method is POST otherwise use $_GET to fetch the camp_id after the form was sent ?>
    <form method="post">
    <select name="camp_id"> 
        <?php foreach($model["campaign"] as &$obj): ?>
            <option 
               <?php // if form is sent and $selectedCampId is not empty ... echo selected = "selected" ---- otherwise echo empty string ?>
               <?php echo ($obj['id'] == $selectedCampId) ? 'selected = "selected"' : ""; ?>>
               <?php echo $obj["name"];?> 
            </option> 
        <?php endforeach;?>
    </select>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two drop down menus where the options are not get from the
I have three identical drop down lists that I'm populating using MySQL data. If
I have two drop downs on a page whose backing bean is Request Scoped.
I have two drop down boxes in my program. When you select an item
In my application i have two drop down boxes first box had origin second
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have a user control in a master page with two drop down lists.
I have one drop down list in my page, which contains two options. What
I have a form with two text boxes, one select drop down and one
I have a drop down which has a method which binds data to it:

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.