convert sql |
Hi guys how can I convert the value of integer to text, example if it is 0 to display not paid and 1 to display paid
On model //get chart public function invoice_chart() { $res = $this->db->query("select payment_status as status, count(*) as total from invoice group by status"); return $res->result_array(); } (09-20-2021, 04:19 AM)Tajar_Dobro Wrote: Hi guys how can I convert the value of integer to text, example if it is 0 to display not paid and 1 to display paid SQL Case
yes , you can.
Code: Select if(payment_status=0,'Not Paid','Paid ') AS status
ikeselayes , you can.
Code: Select if(payment_status=0,'Not Paid','Paid ') AS status (09-20-2021, 11:53 PM)Tajar_Dobro Wrote: ikeselayes , you can. Hi, You could also display the statuses using PHP instead of SQL. Code: function getPaymentStatus($status)
(09-21-2021, 12:51 AM)paulkd Wrote: You could also display the statuses using PHP instead of SQL. +1 for this solution. In my opinion, it’s always better to do formatting outside of SQL query. This way you can change the text later without breaking your app and you can also support multiple languages.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |