如何在codeigniter php中以字幕显示标题
我是PHP的如何在codeigniter php中以字幕显示标题,php,codeigniter,Php,Codeigniter,我是PHP的codeigniter框架的新手。我想在滚动字幕中显示新闻标题我尝试了这个 查看页面 <marquee bgcolor="black"><font color="white"> <?php foreach($news as $row) { $heading=$row->st_head; echo $heading; } ?> </font ></marquee> 控制器 <?p
codeigniter
框架的新手。我想在滚动字幕中显示新闻标题
我尝试了这个
查看页面
<marquee bgcolor="black"><font color="white">
<?php
foreach($news as $row)
{
$heading=$row->st_head;
echo $heading;
}
?>
</font ></marquee>
控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Headlines extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('Headlines_model');
}
public function index()
{
$where_cond = "flg_is_active = 1";
$select_cond = "st_head,in_news_id";
$data['news'] = $this->Headlines_model->select_records($where_cond,$select_cond );
$this->load->view('Headlines',$data);
}
}
如果我显示时没有选框
,则会正确显示数据。但当我使用marquee时,它会给出以下错误
遇到PHP错误
严重性:通知
消息:未定义变量:news
文件名:views/Headlines.php
行号:2
将模型文件的代码张贴到打印($data['news'])会得到什么?您使用的确切代码是什么?html对php没有影响,
foreach
在您的示例中位于第3行而不是第2行。它给foreach一个错误。如果我删除foreach,那么它会给echo带来错误。
<?php
class Headlines_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
$this->table_name = 'tbl_news';
}
public function select_records($where=NULL,$select=NULL,$jointable=NULL,$joinkey=NULL,$per_page=NULL,$limit=NULL,$order_by=NULL, $count = false)
{
if($where!=NULL)
$this->db->where($where);
if($select!=NULL)
$this->db->select($select);
if($jointable!=NULL && $joinkey!=NULL)
$this->db->join($jointable, $joinkey);
if($limit!=NULL || $per_page!=NULL)
$this->db->limit($limit, $per_page);
if($order_by!=NULL)
$this->db->order_by($order_by);
$query = $this->db->get($this->table_name);
if($count==true)
{
return $query->num_rows();
}
else
{
return $query->result();
}
}
}
?>