function mostViewedTracks() {
$this->load->database();
$this->db->select("*");
$this->db->from("file");
$this->db->order_by("views", "desc");
$this->db->limit(8);
$query = $this->db->get();
if($query->num_rows() > 0)
{
$results = $query->result();
}
return array();
}
當我運行這個模型給出了錯誤的的foreach()提供的無效參數無效參數
這是我的看法代碼:
<?php if(!empty($most_viewed)) { ?>
<?php foreach($most_viewed as $row): ?>
<a href="<?php echo base_url('index.php/home/track');?>/<?php echo $row->id;?>" class="list-group-item">
<img class="track-list-img" src="<?php echo base_url('assets/img/music');?>/<?php echo $row->id;?>.jpg">
<div class="list-track-infoo">
<h4 class="list-group-item-heading"><?php echo $row->title;?><span class="badge"><?php echo $row->views;?><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></span> </h4>
<p class="list-group-item-text"><?php echo $row->singer;?></p>
</div>
</a>
<?php endforeach; ?>
<?php} ?>
更新
控制器
function track() {
$id = $this->uri->segment(3);
$data1['track'] = $this->view_models->track($id);
$data1['most_viewed'] = $this->view_models->mostViewedTracks();
$this->load->view('includes/header');
$this->load->view('track', $data1);
$this->load->view('includes/footer');
}
我已經盡了全力來解決這個問題,但一切都是徒勞
提供適當的代碼 –
我已經更新了我的問題 –
您返回數組使用return $結果,請再次檢查;在 –