skyer2000 Posted May 6, 2009 Share Posted May 6, 2009 Got a question on how to display this query correctly with PHP. SELECT papers.papid AS papid,papers.title AS title, keywords.keyword AS keyword FROM papers,keywords WHERE papers.topid = ? AND keywords.topid = papers.topid What I want to do here is only show the papid once, but this one papid may have multiple keywords that are found using this query. How do I make it display multiple keywords, but only one papid? Is this the correct way to go about it? Quote Link to comment https://forums.phpfreaks.com/topic/157155-solved-displaying-mysql-join-data-properly/ Share on other sites More sharing options...
kickstart Posted May 7, 2009 Share Posted May 7, 2009 Hi You could just loop through the returned data in php, and only display the papid and title when they change. Another option would be to group the returned rows by the papid and just concatenate all the key words. SELECT papers.papid AS papid,papers.title AS title, GROUP_CONCAT(keywords.keyword) AS keyword FROM papers,keywords WHERE papers.topid = ? AND keywords.topid = papers.topid GROUP BY papers.papid All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/157155-solved-displaying-mysql-join-data-properly/#findComment-828106 Share on other sites More sharing options...
skyer2000 Posted May 7, 2009 Author Share Posted May 7, 2009 Perfect! Thank you! For anyone who made need more reference on that, this page does a great job explaining it: http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/ Quote Link to comment https://forums.phpfreaks.com/topic/157155-solved-displaying-mysql-join-data-properly/#findComment-828411 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.