ChaosKnight Posted January 11, 2010 Share Posted January 11, 2010 I'm a complete noob when it comes to databases, in the project that I'm busy with there is a column which is filled with a lot of game parks and they are separated with commas, how can I tell the query to return each entry? At the moment I do this like so: SELECT * FROM $table WHERE `country` = '".$country."' AND `active` = 'yes' Please assist Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/188039-mysql-noob-please-help/ Share on other sites More sharing options...
trq Posted January 11, 2010 Share Posted January 11, 2010 Do you mean each entry between the comas? That would need to be done with php, data shouldn't be stored coma separated within database for this (and a few other) reason(s). Quote Link to comment https://forums.phpfreaks.com/topic/188039-mysql-noob-please-help/#findComment-992713 Share on other sites More sharing options...
cags Posted January 11, 2010 Share Posted January 11, 2010 That is a poor table design, you should not have multiple values stored in a single field as this makes it very difficult to do anything with a specific entry from that field. The standard way around this would be to have extra tables. It's not entirely clear from your post what the exact relationship is which makes it difficult to give you an exact design. For this reason I'll make up an example. Let's say you have a table (we'll call it `places`) that stores information on game parks and an example row in your table has a field called `parks` which contains "park1,park2,park3". What you would do is create an extra table called something like `place_parks` which would contain a field for `place_id` and a field for `park` and probably a unique id `park_id`. This way we can select all parks in a place using "SELECT * FROM place_parks WHERE place_id=1" or we can select individual parks using "SELECT * FROM place_parks WHERE park_id=2". Quote Link to comment https://forums.phpfreaks.com/topic/188039-mysql-noob-please-help/#findComment-992714 Share on other sites More sharing options...
ChaosKnight Posted January 11, 2010 Author Share Posted January 11, 2010 I think I'll do it like you suggested, thanks cags, the previous web developer did it like I mentioned, he threw everything into the same table and that is where the mess started, but thanks Quote Link to comment https://forums.phpfreaks.com/topic/188039-mysql-noob-please-help/#findComment-992775 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.