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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:35:50+00:00 2026-06-18T16:35:50+00:00

So I have this drop down list in my form which pull tags from

  • 0

So I have this drop down list in my form which pull “tags” from database as value for drop down options:

<select name="cartags">
   <?php $result = mysql_query("SELECT * FROM Products WHERE ID > '0'");
   while($row = mysql_fetch_array($result))
   {
      echo "<option value=\""; echo $row['Tag']; echo "\""; echo ">"; echo $row['Tag']; echo "</option>";
   } 
   ?>   
</select>

What is my problem? My problem is that I am adding a lot of products into my databas and my code make dropdown list with tags for all this producst even if they have same tag. So what I need is solution how to prevent that same tag appear twice in my drop down.

I am pretty new to PHP and this is my first question here so I really hope that I explained my problem well.

Thanks in advance!

  • 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-18T16:35:51+00:00Added an answer on June 18, 2026 at 4:35 pm

    What is the purpose of WHERE ID > '0'? If ID is an auto-increment then it will always be positive. If not, it should be.

    Why are you using mysql_fetch_array and then only using the associative keys? You should use mysql_fetch_assoc instead.

    Why are you using a new echo every time you want to output a variable? Just concatenate.

    Why are you setting the same string in value as the option’s text? Without a value, it defaults to the text anyway.

    Why are you not using backticks around your column and table names?

    Try this instead:

    <select name="cartags">
    <?php
      $result = mysql_query("SELECT DISTINCT `Tag` FROM `Products`");
      while(list($tag) = mysql_fetch_row($result)) {
          echo "<option>".$tag."</option>";
      }
    ?>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this drop-down list of countries: <select name=country> <option value=>Country...</option> <option value=Afganistan>Afghanistan</option> <option
I have created and html form which have a drop down list. This drop
I have a form which has a drop down list for countries. If the
I have a drop down list (ddlAccount) which i can choose an item from
I have a drop down list on a form view which are both bound
I want to fetch a selected value from a drop down 'select' list of
I have a PHP based form. It has a drop down list which fetches
I have this code which can display drop down in div tag of html.
I have capture change event on drop down select. This drop down field is
I have a drop down list displaying values in a select tag that I

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.