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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:37:57+00:00 2026-06-09T12:37:57+00:00

I am looking for some method to select a php combobox <select> based on

  • 0

I am looking for some method to select a php combobox “<select>” based on results from mysql.

Actually I am working on a php form that will be used to edit existing values in mysql table. My first form will simply pass the id of the record to be edited, and this goes something like this <a href=”editCalendar.php?id=15″>Click to edit</a>

Code on editCalendar.php is as follows:

<?php
    include("dbpath.php");
    $id =  htmlspecialchars($_GET["id"]);

    $sql="Select * from event_Date where eventid=" . $id;
    $result=mysql_query($sql);

    // Check result
    // This shows the actual query sent to MySQL, and the error. Useful for debugging.
    if (!$result) 
    {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        die($message);
    }

    while($row = mysql_fetch_assoc($result))
    {
    $name=$row["EventTitle"];
    $close=$row["OpenOrClose"];
    $remarks=$row["Remarks"];
    $date=$row["EventDate"];
    $type=$row["Type"];
    }
?>

The value obtained in $close will be used to select “SelectClosedOrOpen” on the same form, i.e. the user will get pre selected option from the populated list.

<select id="SelectClosedOrOpen">
<option value="3">Select</option>
<option value="0">Open</option>
<option value="1">Closed</option>
</select>

Means, if $close has 0, then <option value="0">Open</option> must be selected else if $close has 1 then <option value="1">Closed</option> should be automatically selected on formload.

  • 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-09T12:37:58+00:00Added an answer on June 9, 2026 at 12:37 pm

    You’ll just need to write the selected attribute in there. Try this

    <select id="SelectClosedOrOpen">
    <option value="3" <?php echo ($close == 3) ? 'selected="selected"': ''; ?>>Select</option>
    <option value="0" <?php echo ($close == 0) ? 'selected="selected"': ''; ?>>Open</option>
    <option value="1" <?php echo ($close == 1) ? 'selected="selected"': ''; ?>>Closed</option>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I make some UI under IOS5 that enables to select 1 item from some
I am looking to enclose some Oracle components within a Bash script that will
I am looking to do some method chaining. I have the following code: class
I have a simple CMS running PHP/MySQL and I'm looking for the most efficient
Currently, I am using this query in my PHP script: SELECT * FROM `ebooks`
I have some old school looking code that is as follows: IList<KeyValuePair<string, ValuePair>> ServicePairs
I currently have a form that lets a user select an image. After the
I was looking at some jQuery performance tips and ran across this one that
I have an Enumerable<T> and am looking for a method that allows me to
ok, so i have some links that will be generated for some ads on

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.