Q:

Wrap a variable inside implode function with single quotes

I am trying to run a query using an array inside the implode function. 
$dosages = implode(" AND CONCAT(prescription,'-',dosage) =",$doses);
$q=$this->db->query("SELECT account_num 
                     FROM ( 
                     SELECT account_num, CONCAT(prescription,'-',dosage) as script 
                     FROM ci_prescription_history 
                     )a 
                     WHERE script=".implode(' AND script=',$doses));

MySQL keeps saying "Unknown column 'Advair' in 'where clause'". I just want to know if it is possible to wrap the variable inside the implode function with single quotes so when it gets parsed it reads out like this 
SELECT account_num 
FROM ( SELECT account_num, CONCAT(prescription,'-',dosage) as script 
FROM ci_prescription_history 
)a 
WHERE script='Advair-230/21' AND script='Advair-250/50'

A:

Yes, you need to add the quotes to your query and to implode(), like this:
$q=$this->db->query("SELECT account_num 
                 FROM ( 
                 SELECT account_num, CONCAT(prescription,'-',dosage) as script 
                 FROM ci_prescription_history 
                 )a 
                 WHERE script='" . implode("' AND script ='", $doses)) . "'";

