Welcome Guest, Not a member yet? Register   Sign In
Pagination to create page links
#1

[eluser]Unknown[/eluser]
Hi I seem to go round and round looking at examples on pagination, none of which work in the way I need. I have a music website which I built in basic php check www.johnrlhunter.co.uk the thing is that I want to be able to do in codeignigter as I have done in old fashioned php. I have 3 tables songs, recordings and album which are are joined using foreign keys. You click on the recording via its listed song title which gathered from the joined table and it brings up the lyrics and recording info etc. It all works very well however I cannot find any example of this within any of the tutorials. I don't see any evidence that my tables have joined and when I go through the pagination which rather than shows me the title only I get everything just from recording table which in the below example was renamed to news so that I could follow the tutorial and the next paginated page is blank! Please can someone explain where I am going wrong?
Code:
<?php
//controllers/news.php
class News extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('news_model');
                $this->load->library('pagination');
                $this->load->library('table');
}

public function index()
{
  $config['base_url'] = 'http://localhost:8075/news/';
                $data['news'] = $this->news_model->get_news();
                $config['total_rows'] = $this->db->get('news')->num_rows();
  $config['per_page'] = 10;
  $config['num_links'] = 20;
  $config['full_tag_open'] = '<div id="pagination">';
  $config['full_tag_close'] = '</div>';

                $this->pagination->initialize($config);

  $this->load->view('templates/header', $data);
                $data['records'] = $this->db->get('news', $config['per_page'], $this->uri->segment(3));
  $this->load->view('news/index', $data);
  $this->load->view('templates/footer');
}
}
//models/news_model.php
&lt;?php
class News_model extends CI_Model {

    public function __construct()
{
  $this->load->database();
}

    public function get_news($rec_title = FALSE)
    {
        if ($rec_title === FALSE)
{
        $this->db->from('news');
        $this->db->join('song', 'news.idSong = song.id');
        $query = $this->db->get();
        $data=array();

        if($query->num_rows() > 0){
        foreach($query->result_array() as $news)
                {
                $data[] = $news;
                }
            }
            $query = $this->db->get_where('news', array('rec_title' => $rec_title));
            return $data;
            }
        }
}
//views/news/index.php

   echo $this->table->generate($records);

    echo $this->pagination->create_links();
#2

[eluser]CroNiX[/eluser]
Code:
$config['base_url'] = 'http://localhost:8075/news/';
Are you using a route or _remap() or something so you don't have to enter a method?

You might also need to set $config['uri_segment'] for pagination.

Not sure what this line is supposed to be doing as you don't seem to be doing anything with the data:
Code:
$query = $this->db->get_where('news', array('rec_title' => $rec_title));




Theme © iAndrew 2016 - Forum software by © MyBB