[eluser]nicholas.byfleet[/eluser]
Hello. I am trying to show "related posts" in a blogging module of my own CI CMS. This related post section is just a list of 5 of the most recent posts in the same category as the current post being shown. Here is some of the code in my view:
Code:
<?php echo "<h3>{$category->name}</h3><p>{$category->description}</p>";
$this->db->select('id', 'title');
$this->db->order_by('date', 'desc');
$query = $this->db->get_where('posts', array('status' => 'active', 'category' => $category->id), 5, 0);
if ($query->num_rows()) {
echo "<h3>Related Posts</h3><ul>";
foreach ($query->result_array() as $post) {
echo "<li><a >{$post['title']}</a></li>";
}
echo "</ul>";
}
?>
Here's my question: I want to exclude the current post being viewed from the list and was wondering if there is a way to use active record syntax to specify negation in the get_where statement. In normal SQL, I might write:
Code:
$sql = "SELECT * FROM `posts` WHERE `category`='".$category->id."' AND `id` != '".$id."' LIMIT 0,5 ORDER BY `date` DESC;";
In active record syntax, how do I acheive this part of the SQL?:
Code:
AND `id` != '".$id."'
Do you understand my question? I hope I have explained my problem with clarity. In any case, I hope someone can provide some advice. Thanks in advance.