Reputation: 41
I want to select after 4 news the last 12 from a table. I tried but no results.I got the Undefined $news
public function get_all_news_home()
{
$news = array();
# ne conectam la baza de date
$this->load->database();
# selectam stirile de top
$last_news_query = $this->db->query("SELECT * FROM News WHERE Type = 1 AND Ready='Y' ORDER BY Date DESC LIMIT 4");
$last_news = $this->db->query($last_news_query);
$last_news = ($last_news->num_rows()) ? $last_news->result_array() : NULL;
foreach ($last_news as $ln)
{
array_push($news,array('id' => $ln['ID']));
}
$all_news = $this->db->query("SELECT * FROM News WHERE News.Ready = 'Y' AND News.ID NOT IN ('$news') ORDER BY Date DESC LIMIT 12");
if($all_news->num_rows())
{
$all_news = $all_news->result_array();
}
else
{
$all_news = NULL;
}
return $all_news;
}
Help me please.How can I exclude the first 4 id
Upvotes: 2
Views: 5411
Reputation: 94
Just use the limit clause
...
$last_news_query = $this->db->query("SELECT * FROM News WHERE Type = 1 AND Ready='Y' ORDER BY Date DESC LIMIT 0,4");
...
$all_news = $this->db->query("SELECT * FROM News WHERE News.Ready = 'Y' AND News.ID NOT IN ('$news') ORDER BY Date DESC LIMIT 4,12");
...
Upvotes: 0
Reputation: 2112
Try this:
...
$newsIds = implode(',', array_values($news));
...
$all_news = $this->db->query("SELECT * FROM News WHERE News.ID NOT IN ('$newsIds') ORDER BY Date DESC LIMIT 12");
...
Upvotes: 1