0

I have two arrays:

$armortype = array(5,8);

and

$slotarray = array(1,2,3,5,6,7,8,9,10,11,11,12,16);

How do I combine these two in one foreach loop? Here's the code at the moment:

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");
    }
}

My $armor value doesn't come out right.

4

1 回答 1

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");

那应该这样做。放置它而不是两个循环。它只运行一个查询而不是几十个......

于 2013-08-14T22:56:54.107 回答