我有一个PHP代码函数get_news()
。
get_news函数
function get_news(){
if($result = $this->db->query('SELECT * FROM tb_post WHERE post_id<>1 ORDER BY post_date DESC LIMIT 50')){
$return = '';
while($r = $result->fetch_object()){
$return .= '<p>id: '.$r->post_id.' | '.htmlspecialchars($r->post).'</p>';
}
return $return;
}
}
现在,我有一个用于获取数据的php文件
if(isset($_POST) && !empty($_POST['counter']) && (int)$_POST['counter']!=$data['current']){
//the counters are diffrent so get new message list
$data['news'] = '';
$data['news'] .= $db->get_news();
$data['update'] = true;
}
我的问题是,如何在不调用函数的情况下将$db->get_news();
更改为直接查询?
答案 0 :(得分:2)
Try this
$news = '';
if($result = $this->db->query('SELECT * FROM tb_post WHERE post_id<>1 ORDER BY post_date DESC LIMIT 50')){
$return = '';
while($r = $result->fetch_object()){
$news .= '<p>id: '.$r->post_id.' | '.htmlspecialchars($r->post).'</p>';
}
}
$data['news'] = $news;
$data['update'] = true;