如何使用逗号分隔的值从数据库中获取数据

时间:2017-04-30 05:44:27

标签: php mysql mysqli comma

我尝试了这段代码,但它只获取了逗号

中最后一个值的值

我在INVOICEVALUE = 1,2

它只获取2

$INVOICEVALUE = $_REQUEST["INVOICEVALUE"];
$VALUE = explode(',', $INVOICEVALUE);
foreach ($VALUE as $val) {

    $invoiceselected = mysqli_query($link, "select SUM(INVOICE_AMOUNT) as AMOUNT,INVOICE_CODE,INVOICE_STATUS,PAYMENT_STATUS,INVOICE_TRANSACTIONDATE,INVOICE_UNITPRICE,CUSTOMER_ID,CUSTOMER_ID
         from invoice where INVOICE_CODE ='" . $val . "' 
         AND INVOICE_STATUS='CLOSE' AND PAYMENT_STATUS=''
         GROUP BY INVOICE_CODE");
}

1 个答案:

答案 0 :(得分:1)

如果您想获得temp[ctr]INVOICE_CODE = 1的结果,那么您可以使用MySQL IN clause

INVOICE_CODE = 2

希望这有帮助!