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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:07:03+00:00 2026-06-16T15:07:03+00:00

I have a dropdown list which should be displaying the correct value of the

  • 0

I have a dropdown list which should be displaying the correct value of the record retrieved from mysql table. Below is what I have tried so far:

   <strong>Authority Id: *</stong><select name="authid">
   <?php

            $authid = $row['AuthorityId'];
    $selectedId = array(
    5, 6, 7);
    $selection = array(
            5 => "Admin",
            6 => "Employee",
            7 => "Student" );
    foreach($selection as $value){
        $text = $value;
        echo '<option value="'.$selectedId.'" selected="'.$authid.'">'.$text.'</option>';
    }
  ?>
  </select>

But it’s not displaying the correct value. Can someone help me figure out what went wrong here? Thanks.

  • 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-16T15:07:04+00:00Added an answer on June 16, 2026 at 3:07 pm
    <strong>Authority Id: *</strong><select name="authid">
    <?php
    
    $authid = $row['AuthorityId']; // Get $authid from database
    $selection = array( // Create Index Of AuthIDs and AuthNames
        5 => "Admin",
        6 => "Employee",
        7 => "Student" );
    
    foreach($selection as $key => $value) // Loop Through $selection, Where $key is AuthID and $value is AuthName
    {
        echo '<option value="' . $key . '"'; // Start Menu Item
        if ($authid == $key) // Check If AuthID from $selection equals $authid from database
            echo ' selected="selected"'; // Select The Menu Item If They Match
        echo '>' . $value . '</option>'; // End Menu Item
    }
    ?>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdown list on my form which should filter out or display
I have a dropdown list (which holds numbers from 0 to 50) and html
I have a form which contains a dropdown list of countries generated from database.
I have a dropdown list (FK) which I would like to set and display
I have a database of Employees and a dropdown list which I generated with
I have a table where one of it's columns contains a dropdown list (HtmlSelectItems
I have a dropdown list which is populated via a jquery ajax call when
I have two DropDown lists which are already populated from the database. If you
Form contains two dropdown lists created using code below. Both dropdown list elements have
I have a dropdown list which has items bound to it using sql datasource.

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.