我有两个数组:
$armortype = array(5,8);
和
$slotarray = array(1,2,3,5,6,7,8,9,10,11,11,12,16);
如何在一个foreach循环中组合这两个?这是目前的代码:
foreach($slotarray as $slot)
{
foreach($armortype as $armor)
$itempack = mysql_query("SELECT * FROM db WHERE ItemLevel BETWEEN $formlevel1 AND $formlevel2 AND InventoryType =$slot AND Quality<5 AND AllowableClass in ('$formclass', '-1','2047','32767') AND Material=$armor ORDER BY RAND() LIMIT 1");
}
}
我的$ armor值不对。
答案 0 :(得分:0)
$itempack = mysql_query("SELECT *
FROM db
WHERE ItemLevel BETWEEN $formlevel1 AND $formlevel2
AND InventoryType = in ('". implode("', '", $slotarray) ."')
AND Quality<5
AND AllowableClass in ('$formclass', '-1','2047','32767')
AND Material = in ('". implode("', '", $armortype) ."')
ORDER BY RAND()
LIMIT 1");
应该这样做。放置它而不是两个循环。它只运行一个查询而不是几十个...