function get_list_news_same_category($news_data, $limit = 5, $prepare = true) { $db_query = new db_query('SELECT new_id, new_title, new_teaser, new_picture, new_view, new_date, "' . $news_data['cat_name'] . '" AS cat_name FROM news WHERE new_cat_id = ' . $news_data['new_cat_id'] . ' AND new_date <= ' . $news_data['new_date'] . ' AND new_active = 1 AND new_id <> ' . $news_data['new_id'] . ' ORDER BY new_date DESC LIMIT ' . $limit); $list_news = array(); while ($row = mysqli_fetch_assoc($db_query->result)) { if ($prepare) { prepare_news_record($row, 'mobile_small'); } $list_news[] = $row; } return $list_news; }
<?php $db_query = new db_query('SELECT new_id, new_title, new_picture, new_teaser, cat_name FROM news LEFT JOIN categories ON cat_id = new_cat_id WHERE new_active = 1 AND new_date <= ' . TIMESTAMP . ' ORDER BY new_date DESC LIMIT ' . $limit_string); $list_news = array(); while ($row = mysqli_fetch_assoc($db_query->result)) { prepare_news_record($row); $list_news[] = $row; } unset($db_query); $rainTpl->assign('list_news', $list_news);
$row['link_detail'] = generate_news_detail_url($row); $list_hot_day[] = $row; } $rainTpl->assign('list_hot_day', $list_hot_day); //lấy theo category, các bài $list_news_cat = array(); $array_cat = get_category_news(); foreach ($array_cat as $cat_item) { $db_query = new db_query('SELECT new_id, new_title, cat_name, new_picture FROM news LEFT JOIN categories ON cat_id = new_cat_id WHERE new_active = 1 AND new_date <= ' . TIMESTAMP . ' AND new_cat_id = ' . $cat_item['cat_id'] . ' ORDER BY new_date DESC LIMIT 0,5'); $list_temp = array(); $first_news_temp = array(); $temp_count = 0; while ($row = mysqli_fetch_assoc($db_query->result)) { prepare_news_record($row, 'mobile'); $temp_count++; if ($temp_count == 1) { $first_news_temp = $row; } else { $list_temp[] = $row; } } $list_news_cat[] = array('cat_id' => $cat_item['cat_id'], 'cat_name' => $cat_item['cat_name'], 'link_cat' => generate_cat_url($cat_item), 'first_news' => $first_news_temp, 'list_news' => $list_temp); unset($db_query); } $rainTpl->assign('list_news_cat', $list_news_cat);
//nếu không có tin trong 2 ngày gần đây thì lấy từ đầu $db_query = new db_query('SELECT new_id,new_title,cat_name,new_picture,new_teaser FROM news LEFT JOIN categories ON new_cat_id = cat_id WHERE new_cat_id = ' . $record_id . ' AND new_date <= ' . TIMESTAMP . ' ORDER BY new_view DESC LIMIT 1'); $top_list = mysqli_fetch_assoc($db_query->result); unset($db_query); } prepare_news_record($top_list); $rainTpl->assign('top_list', $top_list); //lấy danh sách các bài $page = getValue('page', 'int', 'GET', 0); $page = $page > 1 ? $page : 1; $limit = 10; $limit_string = (int) (($page - 1) * $limit) . ',' . $limit; $list_news = array(); $db_query = new db_query('SELECT new_id, new_title, cat_name, new_picture, new_teaser FROM news LEFT JOIN categories ON new_cat_id = cat_id WHERE new_cat_id = ' . $record_id . ' AND new_date <= ' . TIMESTAMP . ' ORDER BY new_date DESC LIMIT ' . $limit_string); while ($row = mysqli_fetch_assoc($db_query->result)) { prepare_news_record($row, 'mobile_small'); $list_news[] = $row; } $rainTpl->assign('list_news', $list_news);