sql - codeigniter change complex query into active record -


i have codeigniter app.

my active record syntax works , is:

  function get_as_09($q){     $this->db->select('m3');     $this->db->where('productcode', $q);     $query = $this->db->get('productlist');     if($query->num_rows > 0){         foreach ($query->result_array() $row){             $row_set[] = htmlentities(stripslashes($row['m3'])); //build array        }        return $row_set;     }   } 

this effectively

select 'm3' 'productlist' productcode='$1' 

what need convert below query active record type query , return controller per above active record syntax:

select length (select         [length]       ,concat(([width]*1000),([thickness]*1000),replace([productcode],concat(([width]*1000),([thickness]*1000),replace((convert(varchar,convert(decimal(8,1),length))),'.','')),'')) options   [dbo].[dbo].[productlist]) p   options='25100cr' order length 

i picture below not work.

$this->db->select(length); $this->db->from(select  [length],concat(([width]*1000),([thickness]*1000),replace[productcode],concat(([width]*1000),([thickness]*1000),replace((convert(varchar,convert(decimal(8,1),length))),'.','')),'')) options       [dbo].[dbo].[productlist]); $this->db->where(options, $q); $this->db->order(length, desc); 

help appreciated always. again.

you can use sub query way of codeigniter this purpose have hack codeigniter. go system/database/db_active_rec.php remove public or protected keyword these functions

public function _compile_select($select_override = false) public function _reset_select() 

now subquery writing in available , here query active record

$select =   array(                 'length'                 'concat(([width]*1000)',                 'thickness * 1000',                 'replace(productcode, concat((width*1000),(thickness*1000),replace((convert(varchar,convert(decimal(8,1),length))),'.','')),'')) options' ); $this->db->select($select); $this->db->from('productlist');  $subquery = $this->db->_compile_select();  $this->db->_reset_select();  $this->db->select('length'); $this->db->from("($subquery)"); $this->db->where('options','25100cr'); $this->db->order_by('length'); 

and thing done. cheers!!! note : while using sub queries must use

$this->db->from('mytable') 

instead of

$this->db->get('mytable') 

which runs query.

source


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -