Quote:
|
function related_stories($storyid, $related_tags, $category){ // this returns similar stories based on tags in common and in the same category global $db; $related_tags="'".str_replace(", ","', '",$related_tags)."'"; // This gives us the proper string structure for IN SQL statement // Select 10 stories that share tags with the current story and order them by number of tags they share // $sql = "SELECT ".table_links.".link_title, ".table_links.".link_title_url, COUNT( ".table_tags.".tag_link_id ) AS relevance, ".table_tags.".tag_link_id FROM ".table_tags.", ".table_links." WHERE ".table_tags.".tag_words IN ( ".$related_tags." ) AND ".table_tags.".tag_link_id = ".table_links.".link_id AND ".table_links.".link_status = 'published' AND NOT ".table_links.".link_id = ".$storyid; $sql = "SELECT ".table_links.".link_title, ".table_links.".link_title_url, COUNT( ".table_tags.".tag_link_id ) AS relevance, ".table_tags.".tag_link_id FROM ".table_tags.", ".table_links." WHERE ".table_tags.".tag_words IN ( ".$related_tags." ) AND ".table_tags.".tag_link_id = ".table_links.".link_id AND ".table_links.".link_id != ".$storyid; //comment the following line out if you want this to work accross categories // $sql.= " AND ".table_links.".link_category = ".$category; $sql.= " GROUP BY ".table_tags.".tag_link_id, ".table_links.".link_title, ".table_links.".link_title_url ORDER BY relevance DESC LIMIT 10"; // echo $sql; $related_stories = mysql_query($sql); $related_story = array(); while ($rows = mysql_fetch_array ($related_stories, MYSQL_ASSOC)) array_push ($related_story, $rows); return $related_story; } |





Linear Mode




