Jump to content

[SOLVED] query to create a drop down list


mrsrowe

Recommended Posts

Hello

 

I foolishly agreed to create a page that would read data from a table and spit it out into a web page.  Once this was done I was asked to create a search page, which I did, then I was asked to restrict the search criteria to keywords that were in the database table, so I made a quick and dirty fix by downloading all of the terms and populating the drop down list.  Now I have been asked if the drop down list could be populated directly from the table.  I know I should have done that in the first place but there were so many entries and I thought they only wanted a quick soloution, so I didn't create related tables.  Now I'm in a fix.  The keywords field can look like this:

 

apples, cheese, peaches

 

or like this

 

cheese, bread, cherries, apples

 

I want to be able to create a drop down that would read: apples, bread, cheese, cherries, peaches

 

I would like to know if it is possible to write some php that will return all of the data from the column, then look through all of the entries, compare them and then remove the duplicates.  This data should then be able to populate the drop down, I can do that bit.

 

This would mean that I wouldn't have to take their database to bits and create related tables.

 

Perhaps I'm being lazy, perhaps this is more work than it's worth, but I'd like to know if it is possible. 

 

Any help appreciated.

 

thanks

Link to comment
Share on other sites

Hello

 

thanks for the response, but a very quick look at GROUP BY seems to work as long as you have one entry per record.  Unfortunately this isn't a very well formed table so one field can contain multiple keywords, for example one record could be like this

Title  Keywords
Title1: apples, cheese, bread
Title2: apples, cheese, cherries

 

Is that going to work with GROUP BY?

 

Don't I have to put them in an array, do something in the array that finds the individual words and then group them?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.