0

I am using CodeIgniter,

I am able to export the data. I have a column called "status" in the excel sheet. In the status column I am getting 1,0,0,1,-1,2.

Now I have to display the string name in the excel sheet like.

-1="Pending"
 0="Cancel"
 1="Create"
 2="Verified"

I know I have to use CASE but I don't know how to use with Codeignator.

I tried below code.

$this->db->select('tbl_customer.*,tbl_customer_shipping.*,product_order.*, CASE 
WHEN product_order.o_order_status =-1    THEN "Pending" 
WHEN product_order.o_order_status =0    THEN "Cancel"
WHEN product_order.o_order_status =1    THEN "Create"
ELSE "Verified"
END CASE');
$this->db->from('tbl_customer');
$this->db->join('tbl_customer_shipping', 'tbl_customer.cust_id=tbl_customer_shipping.cust_id', 'LEFT');
$this->db->order_by('product_order.o_date_of_added','DESC');

$query = $this->db->get();
$result = $query->result();

But it's not working

I am getting a syntax error

Message: syntax error, unexpected 'CASE' (T_CASE)

Would you help me out in this?

Finally, I found My solution. I forgot to add the name of the column at the end of the case and I used a double inverted comma.

$this->db->select("tbl_customer.*,tbl_customer_shipping.*,product_order.*,CASE 
    WHEN product_order.o_order_status =-1    THEN 'Pending'
    WHEN product_order.o_order_status =0    THEN 'Cancel'
    WHEN product_order.o_order_status =1    THEN 'Create'
    ELSE 'Verified'
END as o_order_status");
12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.