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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:28:36+00:00 2026-05-22T02:28:36+00:00

I am using the follow bit below. I am first querying the db to

  • 0

I am using the follow bit below. I am first querying the db to see all available options but this is for an edit form so i want the drop down to show the previously selected value so i did another query and got the selection. When i do it the way i have it below it will keep repeating the previously selected selection after each available option. HOw to fix this?

<option>Select Sales rep</option>
<?php

$query="select agent_id, agent_name from agent_names where agent_id='$ad' 
order by agent_name asc";
$result=mysql_query($query);
while(list($agent_id, $agent_name)=mysql_fetch_row($result)) {
    echo "<option value=\"".$previousname."\">".$previousselection."</option>
    <option value=\"".$agent_id."\">".$agent_name."</option>";
}


?>

  • 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-05-22T02:28:37+00:00Added an answer on May 22, 2026 at 2:28 am

    Just check if $agent_id equals $previousname (perhaps you mean $previousid?) and echo selected=”selected” if so:

    while(list($agent_id, $agent_name)=mysql_fetch_row($result)) {
        $selected = $agent_id == $previousname;
        echo "<option " . ($selected ? "selected=\"selected\"" : "") . " value=\"".$agent_id."\">".$agent_name."</option>";
    }
    

    Another option is to output the previous selected item before your while loop, and exclude it in your sql query.

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

Sidebar

Related Questions

This is my first experience using the Zend Framework. I am attempting to follow
The question is basically a follow up to this thread: Using a 64 bit
I am having problems using django-tagging . I try to follow the documentation but
Edit 5/11/2011: I guess it's a bit worse than what's below; in my deployed
This is sort of a follow-up to this question . I want to know
I'm using the follow command to get a list of FileSystemInfo's IList<FileSystemInfo> requestFiles =
I understand that I can change a sql table using the follow sp: EXEC
Having follow the tutorial at http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ to integrate the MapKit into my application. However,
I am using temp data as follow in my controllers - very simple, when
I'm using the Jquery Scroll Follow plugin to allow a box to follow along

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.