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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:55:28+00:00 2026-05-20T09:55:28+00:00

I am trying to create a search field that is a dynamically populated drop

  • 0

I am trying to create a search field that is a dynamically populated drop down menu. The code to query the database and populate the menu is as follows:

<form action="<?=$SERVER['PHP_SELF'];?>" method="post" name="nameSearch">
<label for="nameMenu">  
<p>Choose a name from the drop down menu<br />  
to retrieve all the data for that person.</p>  
</label>
<select name="dateMenu" id="dateMenu">
    <option value="0" selected="selected">Choose a name</option>
    <?php
      $sql_search = 'SELECT id, name from $tbl_name';
      $query_search = mysql_query($sql_search);
      while($row = mysql_fetch_array($query_search))
      {
        echo '<option value=' . $row['id'] . '>' . $row['name'] . '</option>';
      }
    ?>
</select>
<input type="submit" name="searchName" value="Find">
</form>

The problem is that because the database holds information that causes it to store the same name repeatedly I get the same name listed as an option in my drop down menu.

The DB looks like so:

----------------------------------------------------------  
| id | name |    uniqueImage     |    date    |   time   |   
----------------------------------------------------------  
| 1  | John | uniqueImage001.png | 2011-03-11 | 14:21:20 | 
| 2  | James| uniqueImage002.png | 2011-03-11 | 14:24:30 | 
| 3  | Joe  | uniqueImage003.png | 2011-03-11 | 14:26:10 | 
| 4  | John | uniqueImage004.png | 2011-03-11 | 14:40:10 | 
| 5  | Joe  | uniqueImage005.png | 2011-03-11 | 14:56:32 | 
| 6  | Joe  | uniqueImage006.png | 2011-03-11 | 15:02:50 | 
| 7  | James| uniqueImage007.png | 2011-03-11 | 15:21:25 | 
| 8  | John | uniqueImage008.png | 2011-03-11 | 15:26:30 | 
----------------------------------------------------------  

and the menu options returned look like so:

<option value="1">John</option>  
<option value="2">James</option>  
<option value="3">Joe</option>  
<option value="4">John</option>  
<option value="5">Joe</option>  
<option value="6">Joe</option>  
<option value="7">James</option>  
<option value="8">John</option>  

What I need is for the drop down menu to be more like this:

<option value="1">John</option>  
<option value="2">James</option>  
<option value="3">Joe</option>

This way I can get all of the unique images associated with a particular user. I don’t need every name in the DB returned in my query, simply each name only one time. I am thinking I may need to set up a relational DB scheme, but I am trying to avoid this. Is there any other way to set this up? 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-05-20T09:55:29+00:00Added an answer on May 20, 2026 at 9:55 am

    Change your database call to be:

    SELECT id, name from $tbl_name group by id, name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a table dynamically in my code behind. My problem
I am trying to create a search for my website over a mySQL database.
I am trying to dynamically filter search results. Every result has tags associated with
I am trying to create an advanced search, where I can let the user
I am trying to create a jQuery click function that will close a div
I'm desperately trying to create a relatively concise search engine with PHP, mySQL and
I'm trying to create a search engine for all literature (books, articles, etc), music,
I'm trying to create a simple search form in Rails, but I think I'm
I have an AlumniRecords table with 60+ columns. I created an AlumniSearchResults class that
I'm building a heavily CRUD based ASP.NET website and I've got to the phase

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.