My problem is that I can't read a piece of data on an individual page. For example, on the front page, I have a number of jokes pulled in from the db; I want to be able to click on a joke and send the user to a url such as jokes.com/read/a-chicken-crossed-the-road. At the moment, it sends me to my custom 404 page with the url being jokes.com/read/1 (1 being the joke_id) and I haven't been able to get past this problem for a while, so I though I would try here.
Here is my setup :
main view:
<a href="<?php base_url()?>read/<?php echo $joke_id ?>"> <p class="joke-content"><?php echo $joke; ?></p></a>
read view:
<?php
foreach($results as $row){
echo "<li>$row->joke</li>";
echo "<li>$row->name</li>";
echo "<li>$row->date_added</li>";
}
?>
controller:
//constructor class enables a function called to be used in any function within this controller
function __construct(){
// Call the Controller constructor
parent::__construct();
$this->load->model('getjokes_m');
}
public function index(){
$this->read();
}
//main jokes functions grabs all the jokes in the database and orders them in their correct category
public function read(){
$data['results'] = $this->getjokes_m->readJokes($this->uri->segment(3));
$this->load->view('template/header');
$this->load->view('template/sidebar');
$this->load->view('content/read', $data);
$this->load->view('template/footer');
}
and finally my model:
function readJokes()
{
$query = $this->db->query('SELECT j.*, c.name FROM jokes j LEFT JOIN category c ON c.category_id = j.category_id WHERE joke_id = ?');
//displays the results if the table has data inside
return $query->result();
}
routes:
$route['default_controller'] = "top";
$route['404_override'] = 'not_found';
$route['register'] = 'login/register';
$route['logout'] = 'login/logout';
$route['admin'] = 'admin/login';
$route['noaccess'] = 'login/noaccess';
I think it might be the sql statement I am using, because it doesn't return any data.
If somebody could point me in the right direction as to why this is not working and to get the first 55 characters in the URL slug, it would be brilliant.