netstormx Posted July 26, 2009 Share Posted July 26, 2009 So I have around 8 columns that have tags for categories. Is there a way I could merge all of these into one column, then just parse by commas though php? Heres what I have now. $query = "SELECT COUNT(ratings.id) as rates,ratings.rating_id,games.gameid as gameid,gametitle as gametitle,gameimage as gameimage,gametitle as gametitle,ROUND(AVG(ratings.rating_num),2) as rating FROM ratings,games WHERE games.gameid = ratings.rating_id AND caturl='$location' OR games.gameid = ratings.rating_id AND tags1='$location' OR games.gameid = ratings.rating_id AND tags2='$location' OR games.gameid = ratings.rating_id AND tags3='$location' OR games.gameid = ratings.rating_id AND tags4='$location' OR games.gameid = ratings.rating_id AND tags5='$location' OR games.gameid = ratings.rating_id AND tags6='$location' OR games.gameid = ratings.rating_id AND tags7='$location' OR games.gameid = ratings.rating_id AND tags8='$location' OR games.gameid = ratings.rating_id AND tags9='$location' GROUP BY rating_id ORDER BY rating DESC LIMIT $offset, $rowsPerPage"; Quote Link to comment https://forums.phpfreaks.com/topic/167550-how-can-i-reduce-this-query-and-use-a-1-column-tagging-system/ Share on other sites More sharing options...
MadTechie Posted July 26, 2009 Share Posted July 26, 2009 You could use CONCAT but I hardly see the point of merging the data into one field just to break it up after! Quote Link to comment https://forums.phpfreaks.com/topic/167550-how-can-i-reduce-this-query-and-use-a-1-column-tagging-system/#findComment-883538 Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 You should definitely redesign your database structure. You should store tags in a separate table. This will prevent such horrific queries. Quote Link to comment https://forums.phpfreaks.com/topic/167550-how-can-i-reduce-this-query-and-use-a-1-column-tagging-system/#findComment-883556 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.