Welcome Guest, Not a member yet? Register   Sign In
Passing Variables to SQL Query
#1

Hello,

I am trying to pass a session variable = userid to a model which runs a sql query then passes the query back to the controller which passes the data to thew view.

Apologies for the newbie question, if you could point me in the right direction or provide a link to some tutorials that would be much appreciated Smile

function functionname($data){
$query = $this->db->query("SELECT * FROM table WHERE column = $data");

return $query->result();

}
Reply
#2

(This post was last modified: 05-07-2015, 02:17 AM by casa.)

about your function, your query is not protected
PHP Code:
$query $this->db->get_where("table_name", array('column' => $data));
// or 
$sql "SELECT * FROM table_name where column =  ?" ;
$query $this->db->query($sql, array($data)) ; 
About session variable,(documentation about CI is very good)
PHP Code:
// create a session variable
$this->session->set_userdata('name''value') ;
// call a session variable
$this->session->userdata('name') ; // return 'value' 
About use function
PHP Code:
// some codes ...
 //...
  
$this->Model_name->functionname($this->session->userdata('name')) ; 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB