0
votes

Controller

public function livefeed($data = NULL) {


    //echo $this->uri->segment(3);exit;
    $this->load->model("home_model");

    $config = array();
    $config["base_url"] = base_url("content/livefeed/");
    $config["total_rows"] = $this->home_model->record_count();
    $config["per_page"] = 10;
    $config["uri_segment"] = 3;

    $config['num_links'] = 2;
    $config['use_page_numbers'] = TRUE;
    $config['page_query_string'] = TRUE;

    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';

    $this->pagination->initialize($config);
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    $data["results"] = $this->home_model->getLiveFeed($config["per_page"], $page);
    $data["links"] = $this->pagination->create_links();

    $this->load->view("live", $data);


}

Model

public function getLiveFeed($limit = NULL, $start = NULL) {

    $this->db->select('*');
    $this->db->where('status', 1);
    $this->db->from('rs_tbl_live');
    $this->db->limit($limit, $start);
    $query = $this->db->get();

    if($query->num_rows() > 0) {

        foreach ($query->result() as $row) {
            $data[] = $row;
        }

        return $data;;
    }
    return false;
}

View

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: controllers/content.php

Line Number: 64

 foreach( $results as $rowTV){
    <div class="unit item movie-item pull-left" data-key="<?=$rowTV->id;?>"><a href="" class="ChannelCov"> <img src='<?=IMAGE_PATH.$rowTV->img;?>' width="100%" 
    alt="#LifeIsMusic <?=$rowTV->name;?>" title="<?=$rowTV->name;?>" /> </a> 
      <h2> <a href=""> <?=$rowTV->name;?> </a> </h2>
    </div>

  }
1
the pagination is visible on first page. when i'm try to call or click on second or next button this error display ** A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: controllers/content.php Line Number: 64 ** and also forget the loop variables Message: Undefined variable: links Message: Undefined variable: results - Mansoor Ahmed Sheikh
Which is line 64? Please state the problem you wish to solve clearly. - Mark Chorley

1 Answers

0
votes

Edit Model with this

public function getLiveFeed($limit = NULL, $start = NULL) {

$this->db->select('*');
$this->db->where('status', 1);
$this->db->from('rs_tbl_live');
$this->db->limit($limit, $start);
$query = $this->db->get();

    if($query->num_rows() > 0) {
       return $query;
    } else {
       return false;
    } 
}

In View Display Like this.

<?php foreach ($results->result() as $rowTV) { ?>
<div class="unit item movie-item pull-left" data-key="<?=$rowTV->id;?>">
    <a href="" class="ChannelCov"> 
        <img src='<?=IMAGE_PATH.$rowTV->img;?>' width="100%" alt="#LifeIsMusic <?=$rowTV->name;?>" title="<?=$rowTV->name;?>" />
    </a>
    <h2><a href=""><?=$rowTV->name;?></a></h2>
</div> 
<?php  }  ?>