PHP using get_where clause in Codeigniter not passing data

activerecordcodeigniterPHPwhere-clause

Hi All I'm new to Codeigniter, I'm trying to get all data relating to the account_id passed from a previous page.

I'm passing the account_id but not passing the name field associated with the account_id. The name field is blank.

I'm getting an error:

Here is my code for the controller:

function input($account_id = '', $name = ''){
   if((int)$account_id > 0){
      $query = $this->db->select('name', $name);
      $query = $this->db->get_where('db_accounts', array('account_id' => $account_id));

      $data['account'] = $query;
      $data['fname']['value']   = $name;
      $data['faccount_id']['value'] = $account_id;
      $data['name']        = '';
      $data['account_id']  = '';
  }

  $this->load->view('manage/input',$data);      
}

Here is my input view form:

<?php

   $data = array(
          'name'  => $fname['value'],
          'account_id' => $faccount_id['value']
        );

echo '<form action="/manage/edit" method="post" accept-charset="utf-8">';
echo form_hidden($data);

echo $account_id .' Account ID'.
    form_input($faccount_id); 
echo $name .' Name'.
    form_input($fname); 

$data = array('name' => 'submit', 'value' => 'Update Account', 'class' => 'submit');
echo form_submit($data);

  ?>
 <?php echo form_close(); ?>

Best Answer

i believe get_where just preps your query

$query->row_array() should return your result as an array

$query = $this->db->get_where('db_accounts', array('account_id' => $account_id));
$result = $query->row_array();

For the second part of your question it looks like there is a lot going on. What is the value of $name in your input function? Are you actually passing a value to input? Make sure that name is set in your input function or else it will just be an empty string.

Related Topic