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

  • Home
  • SEARCH
  • 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 8251933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:24:02+00:00 2026-06-08T00:24:02+00:00

I have made a dropdown box that is filled by a query that looks

  • 0

I have made a dropdown box that is filled by a query that looks for company names from company name database, these names also have and ID number that I don’t want displayed but are looked up in the query. I need the ID number to link to sites of the company so somehow when I hit the submit button on the site page it finds the ID number by looking at the position value and relating that to the position on the query array I just don’t know what to do. If it helps this is how I fill the dropbox:

mysql_select_db("DB", $con);
$query = "SELECT Company_Name, ID FROM company_table";
$result = mysql_query($query) or die(mysql_error());
$options ='';
$num = 0;
while ($row=mysql_fetch_array($result)) {
$num = $num+1; 
$options.= "<OPTION VALUE=\"$num\">".$row["Company_Name"]; 
}
<SELECT NAME=thing> 
<OPTION VALUE=0>Choose 
<?=$options?> 
</SELECT>

Any Ideas?

  • 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-08T00:24:04+00:00Added an answer on June 8, 2026 at 12:24 am

    There are two immediate ways this can be done. One is to keep it the way you have it using an index, $num; the other way is to use the actual company id field, ID. If you stick with the index of $num, when the user submits the form (i.e. – selects a company), you will have to re-query the database and re-loop through the results to find the specific company (or you could use a LIMIT/OFFSET; notes at end of answer).

    I would recommend using the actual company id in your form:

    while (($row = mysql_fetch_assoc($result))) {
        $options.= '<option value="' . $row['ID'] . '">' . $row["Company_Name"] . '</option>'; 
    }
    

    This will generate a list of options, like you currently have, except the value of each will be the specific company id. When the user submits the form, let’s assume the form is using POST, you can get the ID with:

    $companyId = (isset($_POST['thing']) && is_numeric($_POST['thing'])) ? intval($_POST['thing']) : false;
    $results = mysql_query('SELECT * FROM company_table WHERE ID=' . $companyId);
    

    .. and then process as you desire.

    I use $_POST['thing'] in the above example as that is what your code-example has the select field named. Also, I make the assumption that ID is an integer.

    If the actual ID needs to remain hidden, as specified, the index of $num can be used with MySQL’s LIMIT/OFFSET as follows:

    $selectedCompany = (isset($_POST['thing']) && is_numeric($_POST['thing'])) ? intval($_POST['thing']) : -1;
    if ($selectedCompany >= 0) {
        $query = "SELECT Company_Name, ID FROM company_table LIMIT " . $selectedCompany . ", 1";
        // process as desired
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a code that read data from flash Nand (without filesystem). fd
Have a PHP/MySQL form with a dropdown box containing a list of 350 names.
I have a simple form that has a list (dropdown list generated from a
I have made a jQuery toggle for a menu that I had in mind.
I have made a map of functions. all these functions are void and receive
I have 3 dropdown boxes (combo box) in asp.net environment. They are all optional,
I have a custom drop down box I have made and focus can be
So i have this dropdown made in html/css/js.. it slides down on mouseover, but
I have made a dropdown menu. I need a 25px x 25px image to
I have made a small dropdown menu with jQuery and have binded the show

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.