我有來自數據庫的多選字段。例如我在頁面中選擇申請(storeform.php):
<select name="store[]" multiple="multiple">
<option value=1>Outlet 1</option>
<option value=2>Outlet 2</option>
<option value=3>Outlet 3</option>
<option>.......</option>
</select>
我想從上面的選擇字段值使用PHP崗位數據庫,並把值放入Query.This是我寫的其他頁面調用(storetable.php):
<?php
$storenum=$_POST['store'];
foreach($storenum as $snumber)
{
//this part i need to get the values and put the values into Query.
//for example the $storenum hold values $1 and $2, so $1,$2 i need to put in Query.
}
$query="SELECT sum(a.netamt) as netamt, b.store_name,
c.monusage,c.monusage/sum(a.netamt)*1000 as duh
FROM site_sales a JOIN site_store b ON b.storenum = a.storenum
JOIN site_salmonusage c ON b.storenum = c.storenum
WHERE c.month = '$date211' AND (a.storenum='$1' OR a.storenum='$2') AND a.busidate >= '$date1' AND a.busidate <='$date2'
GROUP BY a.storenum order by duh"
/* code continue */
你到目前爲止嘗試過什麼? – arielnmz
我只是使用['IN'條件](https://www.techonthenet.com/sql/in.php),例如'a.storenum IN(?)'並將該參數綁定到'implode(' ,',$ _POST ['store'])''。您應該確保所有'$ _POST ['store']'值都是數字,我想是 – Phil
您使用MySQLi或PDO與數據庫進行交互嗎? – Phil