Welcome Guest, Not a member yet? Register   Sign In
Views
#2

[eluser]gigas10[/eluser]
I'm not sure what you mean by create on the fly.

Your updated view
Replace the link's id with <?=$item->id;?>, for some reason it won't let me put it that way into the forums.
Code:
<!DOCTYPE HTML>
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;Sports&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    <h1>Sports</h1>
    <ul>
        &lt;?php foreach($query as $item): ?&gt;
        <li><a href="Sports/view/$id">&lt;?=$item->title;?&gt;</a></li>
        &lt;?php endforeach; ?&gt;
    </ul>
&lt;/body&gt;
&lt;/html&gt;

A new view, responsible for displaying the sports information, named view.php
Code:
<!DOCTYPE HTML>
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;Sports&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    <h1>&lt;?=$sport->title;?&gt;</h1>
    &lt;!--Any other sports data you need to display--&gt;
&lt;/body&gt;
&lt;/html&gt;

Updated model, contains new method get($id)
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sports_model extends CI_Model {
    function get_all()
    {
        $query = $this->db->query('SELECT id, title FROM sports');
        return $query->result();
    }

    function get($id)
    {
        $query = $this->db->query('SELECT id, title FROM sports WHERE id='.$id.'');
    }
}

Updated controller with new method view
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sports extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model('sports_model');
    }
    public function index()
    {
        $data['query'] = $this->sports_model->get_all();
        $this->load->view('sports_view', $data);
    }

    public function view($id)
    {
        $data['sport'] = $this->sports_model->get($id);
        $this->load->view('view', $data);
    }
}

/* End of file sport.php */
/* Location: ./application/controllers/sport.php */


Messages In This Thread
Views - by El Forum - 05-21-2011, 12:57 PM
Views - by El Forum - 05-23-2011, 01:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB