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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:26:25+00:00 2026-06-08T12:26:25+00:00

Imagine that: A field that could be YES or NO -> Active: Yes |

  • 0

Imagine that:

A field that could be YES or NO -> Active: Yes | Active: No

So, i got a query that returns it for each client.

I want to show the results in a form, and I should be able to edit that and save on BD again.

I can almost do it, but I need that the default value be wich was already saved on BD, and what I have atm seems show the last row or something.

I want that show the current status or be able to change it for (Yes or NO)

It goes like this for the combobox:

$sql = "SELECT * FROM client,sector WHERE client.idClient = '$id' AND sector.idSector=client.Sector_idSector ";
$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
{

<select name="alterar_sector" id="sectorbox" >
    <?php 
    while($row = mysql_fetch_array($result))
    {
    echo '<option value="'.$row['idSector'].'">'.$row['idSector'].' - '.$row['Nomesec'].'</option>';
    }

    ?>
    </select>

}

Dont give importance of info displayed like “sector” or even the query etc..

Resume:

I want that combobox could display the current value as default and give a list of anothers possible values to change.

Thank you 🙂

  • 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-08T12:26:26+00:00Added an answer on June 8, 2026 at 12:26 pm

    I might have missed the point of the question, but are you asking how you can make a from field appear as being selected?
    Simple modify this line:

    echo '<option value="'.$row['idSector'].'">'.$row['idSector'].' - '.$row['Nomesec'].'</option>';
    

    To have:

    echo '<option selected="selected" value="'.$row['idSector'].'">'.$row['idSector'].' - '.$row['Nomesec'].'</option>';
    

    If that is the particular option you want selected…

    You might have something like this:

    while($row = mysql_fetch_array($result))
    {
      if ($sectorActive != $row['idSector']) {
        echo '<option value="'.$row['idSector'].'">'.$row['idSector'].' - '.$row['Nomesec'].'</option>';
      }else{
        echo '<option selected="selected" value="'.$row['idSector'].'">'.$row['idSector'].' - '.$row['Nomesec'].'</option>';
      }
    }
    

    Ok, so if you want a select field to have a default value you need to have selected="selected" as a paramater value in the <option> element. As per your example like this:

    <select name="gender">
      <option>Male</option>
      <option>Female</option>
      <option selected="selected">Other</option>
      <option>Not Specified</option>
    </select>
    

    So if you have a query pulling records and you want to make sure you have the right value selected. You need to have a variable that changes with each record – and you need to install some logic in that HTML insert, like this: (this example will output the same HTML as the example above…)

    <?
        $usersGender = 'Other'; // This value should be set via the loop, and from a database value.
    ?>
    <select name="gender">
      <option <?=($usersGender=='Male')?'selected="selected"':''?>>Male</option>
      <option <?=($usersGender=='Female')?'selected="selected"':''?>>Female</option>
      <option <?=($usersGender=='Other')?'selected="selected"':''?>>Other</option>
      <option <?=($usersGender=='Not Specified')?'selected="selected"':''?>>Not Specified</option>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine that you want to send any Serializable class to the client side of
Imagine that I have a form in a flash application with two fields, input1
Imagine that I want to create an array from another array like this: $array
imagine that I have a Form with 9 controls (TabbedStuffControl) in a 3x3 tile,
Imagine a table that has two fields, a smalltimedate and an int and about
Imagine that during a foreach(var item in enumerable) The enumerable items change. It will
Imagine that I have a nice Deck class, in the best OO fashion. It
Imagine that i have the following code: <a:repeat value=#{bean.getList()} var=x > <li class=la> <span>
Imagine that HTML page is a game surface (see picture). User can have n
Imagine that your web application maintains a hit counter for one or multiple pages

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.