Php 我如何不仅通过id,而且还通过一列来获取
这是我的 型号Php 我如何不仅通过id,而且还通过一列来获取,php,codeigniter,web,Php,Codeigniter,Web,这是我的 型号 public function get_news($NewsId= FALSE) { if ($NewsId === FALSE) { $this->db->select('*'); $this->db->from('news'); $this->db->where('Status' , 1); $this->db->wh
public function get_news($NewsId= FALSE)
{
if ($NewsId === FALSE)
{
$this->db->select('*');
$this->db->from('news');
$this->db->where('Status' , 1);
$this->db->where('Language' , 2);
return $query->result_array();
$config['per_page']; $this->uri->segment(3);
}
$query = $this->db->get_where('news', array('NewsId' => $NewsId));
return $query->row_array();
控制器
public function single($NewsId)
{
$data['news_item'] = $this->news_model->get_news($NewsId);
if (empty($data['news_item']))
{
show_404();
}
$data['NewsId'] = $data['news_item']['NewsId'];
$this->load->view('news/single', $data);
}
查看
<?php echo $news_item['TittleNews'];?>
我还有另外一个观点,那就是我的所有新闻表,我想创建阅读更多的内容,我已经创建了我的代码,它工作得很好
要使用NewsId和另一列使“阅读更多”,这意味着首先检查NewsId,然后检查其他列,然后在我的视图上显示,该视图是单独的您可以使用如下模型方法:
function getBy($data){
foreach($data as $key=>$value){
$this->db->where($key,$value);
}
$query = $this->db->get('users_table');
return $query->row(); //or $query->result(); as you want
}
那你就把它叫做
$this->model->getBy(
array(
'username'=>'Mark',
'id'=>'90',
'email'=>'asd@asd.com'
);
);
显然,您可以尽可能地扩展模型方法请清楚地告诉我们您想要什么。用那种英语,我无法理解你的意思。对不起,你的要求我不太清楚。@rafiq的问题是你的问题标题与问题内容无关,真的听不懂你说的:D