Convictions Posted March 29, 2008 Share Posted March 29, 2008 First, thank you for taking the time to read this. I have a table named `Tags` which consists of my site members tags (words stripped from their about me sections) - this table has two columns: Tag, profile. Tag is the word, profile is the ID of the member. I am trying to have a query that outputs a member's tags that at least matches one other member's tag in the database. I have tried everything I can think of. Here is my code, and error generated: $sTagsQuery = "SELECT `Tag` as `user_tag` FROM `Tags` WHERE `Tags`.`profile`='{$p_arr['ID']}' AND EXISTS (SELECT `Tag` FROM `Tags` WHERE `Tag` = `user_tag` AND COUNT( `Tags`.`Tag` ) > 2 GROUP BY `Tags`.`Tag`)"; $rTags = db_res( $sTagsQuery ); while( $aTags = mysql_fetch_assoc( $rTags ) ) { $sTagsAddon .= "<a href='" . $site['url'] . "search_result.php?tag=" . $aTags['user_tag'] . "'>" . $aTags['user_tag'] . "</a>, "; } The error is: Query: SELECT `Tag` as `user_tag` FROM `Tags` WHERE `Tags`.`profile`='1' AND EXISTS (SELECT `Tag` FROM `Tags` WHERE `Tag` = `user_tag` AND COUNT( `Tags`.`Tag` ) > 2 GROUP BY `Tags`.`Tag`) Mysql error: Invalid use of group function Any help will be greatly appreciated! Thank you, Chris www.convictionscommunity.com Quote Link to comment https://forums.phpfreaks.com/topic/98458-query-of-multiple-user-tags-help/ Share on other sites More sharing options...
fenway Posted March 29, 2008 Share Posted March 29, 2008 You can't check count in the where clause.... that subquery should be SELECT `Tag` FROM `Tags` WHERE `Tag` = `user_tag` GROUP BY `Tags`.`Tag HAVING COUNT( `Tags`.`Tag` ) > 2 Quote Link to comment https://forums.phpfreaks.com/topic/98458-query-of-multiple-user-tags-help/#findComment-503909 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.