Again a question about CodeIgniter. I'm trying to get information out of my database, which is not that dificult. I get all the data but want to add an condition, the author_id has to be the same as $id. My code:
<?php
class BookModel extends CI_Model {
public function get_book($id){
$this->load->database();
$query = $this->db->query('SELECT book_id, book_title, book_publisher, book_summary FROM books WHERE author_id = $id');
return $query->result();
}
}
?>
If I echo $id it shows my ID. But in the SQL function it is failing. Also, when i hardcode a number like
WHERE author_id = 1
It load proberly.
This is the error i get:
Error Number: 1054
Unknown column '$id' in 'where clause'
SELECT book_id, book_title, book_publisher, book_summary FROM books WHERE author_id = $id
What am I doing wrong?
$this->load->database();why not autoload so you dont have to place this$this->load->database();every where$autoload['libraries'] = array('database');