Hi’
I’m having an issue filtering my posts returned for a blog.
For example: http://roller.rollertestingserver.co.uk/blog/categories/applications/
Shows all the post related assigned to applications which has a category id which is ‘1’.
It is also on this page pulling through an article which has a category id =‘13’ & ‘14’ & ‘15’
From the SQL query below I know that I am using LIKE in the query and this is the reason why however I’m unsure how to make it unique so it pulls back only LIKE ‘1’ and not ‘13’, '14 etc
Any tips?
public function getBlogPostsByCategoryId($id) {
$db = db::getInstance();
if ($result = $db->query("SELECT * FROM `blogs` WHERE `blog_show_live` = 1 AND `blog_categories` LIKE'%".$db->escape($id)."%'")) {
if ($rows = $db->getrows($result)) {
foreach ($rows as &$row) {
$row['blog_categories_names'] = $this->getCategoryNamesFromId($row['blog_categories']);
$row['blog_tags_names'] = $this->getTagNamesFromId($row['blog_tags']);
}
return $rows;
}
}
}
public function getCategoryNamesFromId($categories) {
$db = db::getInstance();
//for each entry check and pull back name and output into array
$list = explode(",",substr($categories,0));
foreach($list as $item) {
if($result = $db->query("SELECT category_name, category_slug FROM categories WHERE category_id IN ($categories)")) {
$res = array();
while ($row = $db->getrow($result))
$res[] = $row;
return $res;
}
}
}
public function getTagNamesFromId($tags) {
$db = db::getInstance();
//for each entry check and pull back name and output into array
$list = explode(",",substr($tags,0));
foreach($list as $item) {
if($result = $db->query("SELECT tag_name, tag_slug FROM tags WHERE tag_id IN ($tags)")) {
$res = array();
while ($row = $db->getrow($result))
$res[] = $row;
return $res;
}
}
}