mrsrowe Posted January 21, 2008 Share Posted January 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87053-solved-query-to-create-a-drop-down-list/ Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Sounds like you can just do a GROUP BY in SQL. Quote Link to comment https://forums.phpfreaks.com/topic/87053-solved-query-to-create-a-drop-down-list/#findComment-445192 Share on other sites More sharing options...
mrsrowe Posted January 21, 2008 Author Share Posted January 21, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/87053-solved-query-to-create-a-drop-down-list/#findComment-445228 Share on other sites More sharing options...
Bauer418 Posted January 21, 2008 Share Posted January 21, 2008 Temporary tables or large PHP arrays. Either way the table structure is extremely inefficient to be doing this with. Quote Link to comment https://forums.phpfreaks.com/topic/87053-solved-query-to-create-a-drop-down-list/#findComment-445231 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 You'll be better off just making a new table. Quote Link to comment https://forums.phpfreaks.com/topic/87053-solved-query-to-create-a-drop-down-list/#findComment-445236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.