• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Active Queries problem

#1
Here is my query

Code:
$this->db->select('amount AS SavingAmount');
$query  = $this->db>get_where('cashman_trial_balance',array('category_id'=>'176','clientId'=>$user['UserID'],'year'=>$year));

On checking in browser its generating this query below


Code:
SELECT *, *, `amount` AS SavingAmount FROM (`cashman_trial_balance`) WHERE `category_id` = '176' AND `clientId` = '122' AND `year` = '2015/2016'

I dont know from where the two stars coming from?

Controller code
Code:
$som_var = $this->client->statistics();

Model code
Code:
function statistics()
{

$b = $this->get_balances();
return $b
}
function get_balances()
{
$this->db->select('amount AS SavingAmount');
$query = $this->db->get_where('cashman_trial_balance',array('category_id'=>'176','clientI‌​d'=>$user['UserID'],'year'=>$year));
return $query->result();
}
Reply

#2
I don't think this is the code which causes problem. Try this and I bet you will see double * there anyway.
PHP Code:
function get_balances()
{
 
 die($this->db->get_compiled_select('cashman_trial_balance'));

Remember that you can construct single query using multiple methods. Also, do you use CodeIgniter 3.0?
Reply

#3
(07-08-2015, 07:38 AM)gadelat Wrote: I don't think this is the code which causes problem. Try this and I bet you will see double * there anyway.


PHP Code:
function get_balances()
{
 
 die($this->db->get_compiled_select('cashman_trial_balance'));

Remember that you can construct single query using multiple methods. Also, do you use CodeIgniter 3.0?

I am using 2.x last version

But thanks for you reply , I configured the error its due to db prefix if I am using the db prefix as "abc" then every active query has double * but when I use abc_ then there is only one * and the query runs fine. May be this proble be in 3.x version also.
Reply

#4
Even one * indicates that some code in your application which you have not included here is changing your database query. This behavior is not caused by CodeIgniter itself in either version 2 or 3.
Reply

#5
Same problem appears again

Here what I am doing

model.php


Code:
function a()
{
$record['comparitive_dividend'] = $this->get_comparative_dividends($trail_balance_year);
return $record;
}

public function get_comparative_dividends($year = null)
{
$user = $this->session->userdata('user');
$this->db->select('amount');
$where = array(
'clientId' => $user['UserID'],
'category_id' => 174,
'year' => $year
);
$record = array();
$query = $this->db->get_where('cashman_trial_balance',$where);
echo $this->db->last_query();
if($query->num_rows() > 0)
{
$result = $query->result();
$record['current_year'] = $result[0]->amount;
}else{
$record['current_year'] = 0;
}

$year = explode('/',$year);
$year[0] = ($year[0]-1);
$year[1] = ($year[1]-1);
$year = implode('/',$year);
$this->db->select('amount');
$where = array(
'clientId' => $user['UserID'],
'category_id' => 174,
'year' => $year
);

$query = $this->db->get_where('cashman_trial_balance',$where);
if($query->num_rows() > 0)
{
$result = $query->result();
$record['previous_year'] = $result[0]->amount;
}else{
$record['previous_year'] = 0;
}
return $record;
}


The above code ouputs
Code:
SELECT *, * FROM (`cashman_trial_balance`) WHERE `clientId` = '145' AND `category_id` = 174 AND `year` = '2014/2015'

The two stars causes the query to break.
Reply

#6
Do you have a call to $this->db->start_cache() somewhere that you're not showing here? Has your database library been modified in any way? Are you using a third party database driver?

These are pretty much the only things I can think of that would cause this behavior.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.