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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:05:50+00:00 2026-06-12T13:05:50+00:00

I have in my php $sel = <option> one </option> <option> two </option> <option>

  • 0

I have in my php

$sel = "
    <option> one </option>
    <option> two </option>
    <option> thre </option>
    <option> four </option>
";

let say I have an inline URL = site.php?sel=one

if I didn’t saved those options in a variable, I can do it this way to make one of the option be SELECTED where value is equal to $_GET[sel]

<option <?php if($_GET[sel] == 'one') echo"selected"; ?> > one </option>
<option <?php if($_GET[sel] == 'two') echo"selected"; ?> > two </option>
<option <?php if($_GET[sel] == 'three') echo"selected"; ?> > three </option>
<option <?php if($_GET[sel] == 'four') echo"selected"; ?> > four </option>

but the problem is, I need to save those options in a variable because I have a lot of options and I need to call that variable many times.

Is there a way to make that option be selected where value = $_GET[sel] ?

  • 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-12T13:05:51+00:00Added an answer on June 12, 2026 at 1:05 pm

    Just use the array of options, to see, which option is currently selected.

    $options = array( 'one', 'two', 'three' );
    
    $output = '';
    for( $i=0; $i<count($options); $i++ ) {
      $output .= '<option ' 
                 . ( $_GET['sel'] == $options[$i] ? 'selected="selected"' : '' ) . '>' 
                 . $options[$i] 
                 . '</option>';
    }
    

    Sidenote: I would define a value to be some kind of id for each element, else you may run into problems, when two options have the same string representation.

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

Sidebar

Related Questions

I have two pages name one.php and two.php in one.php i have a combo
I have php mysql application and i want the phone numbers be saved in
I have list select: <select id=sel> <option id=a1 value=volvo>Volvo</option> <option id=a2 value=saab>Saab</option> <option id=a3
I am using a autocomplete http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ And below i have two pages index.php and
I have php two servers with different versions of php, and am having trouble
I have PHP code to do a simple MySQL database search with only two
I have the following dropdown box <form name=myform method=POST ACTION=songs.php> Select Category: <select id=sel
I have php code that puts some values into an Array as follows: $hunter=addslashes($MessageArray[1]);
I have PHP script works without problems, like this : while($row4 = mysql_fetch_array($result4)) {
I have PHP snippets like this ( snippet.php ): <?php $some_param = some_function(); ?>

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.