I like the way this website shows tags count like javascript× 988307 . I want to do same on my website. Please suggest me best approach to do this with php and mysql. one way to doing this is simply counting keywords which i guess that will be a heavy process. Thanks
1条回答 默认 最新
dtyw10299 2015-11-22 15:58关注The database should have a separate foreign key table which contains only the keywords.
QuestionTable(ID, title, body, ...) FlagTable(ID, name) QuestionFlagTable(ID, IDquestion, IDflag) $sql = "SELECT COUNT(*), f.ID, f.name" . " FROM QuestionFlagTable qf" . " INNER JOIN FlagTable f ON (f.ID = qf.IDflag)" . // optional WHERE (e.g. only specific flags) " GROUP BY f.ID, f.name" . // optional HAVING (e.g. min. count) // optional ORDER BY (e.g. by name or count) "";You can, of course, search the question body for keywords, but that is a very db-heavy process. Think of something like this:
$sql = "SELECT COUNT(*) FROM QuestionTable WHERE body LIKE ?"; $sth = $pdo->prepare($sql); $sth->execute(array('%' . $keyword . '%'));本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报