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
https://forums.phpfreaks.com/topic/87053-solved-query-to-create-a-drop-down-list/
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?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.