0

我正在尝试使用 implode 函数中的数组运行查询。

$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 一直在说“'where 子句'中的未知列'Advair'”。我只是想知道是否可以用单引号将变量包装在 implode 函数中,所以当它被解析时,它会像这样读出

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'
4

2 回答 2

1

是的,您需要将引号添加到您的查询和 中implode(),如下所示:

$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)) . "'";
于 2013-05-01T19:24:27.540 回答
0

编辑 这是我所做的修复它

 foreach ($accounts as $account) {
     $q=$this->db->query("SELECT account_num 
     FROM ( 
     SELECT account_num, CONCAT(prescription,'-',dosage) as script 
     FROM ci_prescription_history 
     )a 
     WHERE script='".implode("' OR script ='",$doses)."' AND account_num=$account");
 }
于 2013-05-01T20:07:35.743 回答