Welcome Guest, Not a member yet? Register   Sign In
CONCAT inside a select function
#1

[eluser]webmarkcompt[/eluser]
Hello everyone

It's possible to concat two values inside this select function?
Such as categories.name as cname and subcategories.name as subcategory ?
Code:
function getdatatableajaxcost()
   {

    $this->load->library('datatables');
    $this->datatables
    
    
  ->select("

            products.id as productid,
            products.image as image,
    
            products.code as code,
          
            categories.name as cname,
            subcategories.name as subcategory,
            products.cost,
            products.price,  
            products.details", FALSE)

            ->from('products')
            ->join('categories', 'products.category_id=categories.id', 'left')
            ->join('subcategories', 'products.subcategory_id=subcategories.id', 'left')


            ->group_by("products.id");

The idea is retrieve both values on the same column inside a jquery datatable.
Any sugestion?

#2

[eluser]larsonator[/eluser]
Should be, just put it in your select statement.
The Active record essentially a query builder,

try something like this:
Code:
function getdatatableajaxcost()
   {

    $this->load->library('datatables');
    $this->datatables
    
    
  ->select("

            products.id as productid,
            products.image as image,
    
            products.code as code,
            CONCAT(categories.name, ' ', subcategories.name) as catcombined,
            categories.name as cname,
            subcategories.name as subcategory,
            products.cost,
            products.price,  
            products.details", FALSE)

            ->from('products')
            ->join('categories', 'products.category_id=categories.id', 'left')
            ->join('subcategories', 'products.subcategory_id=subcategories.id', 'left')


            ->group_by("products.id");
#3

[eluser]webmarkcompt[/eluser]
[quote author="larsonator" date="1412721324"]Should be, just put it in your select statement.
The Active record essentially a query builder,

try something like this:
Code:
function getdatatableajaxcost()
   {

    $this->load->library('datatables');
    $this->datatables
    
    
  ->select("

            products.id as productid,
            products.image as image,
    
            products.code as code,
            CONCAT(categories.name, ' ', subcategories.name) as catcombined,
            categories.name as cname,
            subcategories.name as subcategory,
            products.cost,
            products.price,  
            products.details", FALSE)

            ->from('products')
            ->join('categories', 'products.category_id=categories.id', 'left')
            ->join('subcategories', 'products.subcategory_id=subcategories.id', 'left')


            ->group_by("products.id");
[/quote]

It worked like a charm!

A big thanks!




Theme © iAndrew 2016 - Forum software by © MyBB