[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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Sports</title>
</head>
<body>
<h1>Sports</h1>
<ul>
<?php foreach($query as $item): ?>
<li><a href="Sports/view/$id"><?=$item->title;?></a></li>
<?php endforeach; ?>
</ul>
</body>
</html>
A new view, responsible for displaying the sports information, named view.php
Code:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Sports</title>
</head>
<body>
<h1><?=$sport->title;?></h1>
<!--Any other sports data you need to display-->
</body>
</html>
Updated model, contains new method get($id)
Code:
<?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:
<?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 */