我有一个包含大约300或400个元素的数组。我使用foreach
循环来处理每个数组元素,如下所示:
$cnt=0;
foreach($resIds as $resId)
{
$cnt++;
//my queries and other code
}
我的问题是上面的代码导致内部服务器错误。
如果我在循环中放入一个条件,它对前160个循环工作正常,如:
$cnt=0;
foreach($resIds as $resId)
{
$cnt++;
if($cnt<=160)
{
//my queries and other code
}
}
如果我将$cnt
变量设置为161,则会出现内部服务器错误错误。
任何人都可以帮我吗?
这是代码
foreach($resIds as $resId)
{
$cnt++;
if($cnt<=160)
{
$transRes = $conn->query('select * from bb_users where id = '.$resId.' and deleted=0');
while($trans = $transRes->fetch())
{
$user = $cartObj->getUserInfo($trans['Session_Id']);
$cartRes = $conn->query('select * from bb_cart where Session_Id = "'.$user['Session_Id'].'" and deleted=0');
$cartdetail = '';
$finaltotal = '';
$productregisterRes = $conn->query("Select * from product_register where OrderId = '".$user['OrderId']."'")->fetch();
while($cart = $cartRes->fetch())
{
$ProductId = $cart['ProductId'];
$ProductName = $cart['ProductName'];
if($cart['Color']!="")
{
$freeproductname = stripslashes($productregisterRes['FREEProductName']);
$freeproductname = str_replace(",Lady Gaga featuring (Born This Way & Bad Romance)", "", $freeproductname);
$ProductColor = '['.$cart['Color'].']';
}
else
{
$freeproductname ="";
$ProductColor ="";
}
$ProductQty = $cart['ProductQty'];
$ProductPrice = $cartObj->getpriceformat($cart['ProductPrice']);
$Discount = $cartObj->getpriceformat($cart['Discount']);
$TotalPrice = $cartObj->getpriceformat($cart['TotalPrice']);
$finaltotal += $cart['TotalPrice'];
$cartdetail .='<tr>
<td align="left" width="40%">'.stripdata($ProductName).'<br/><I>'.$freeproductname.'<br/>'.$ProductColor.'</I></td>
<td align="center" width="15%">$'.$ProductPrice.'</td>
<td align="center" width="15%">'.$ProductQty.'</td>
<td align="center" width="15%">$'.$Discount.'</td>
<td align="right" width="15%" style="padding-right:45px">$'.$TotalPrice.'</td>
</tr>';
}
$VoucherCode=$crypt->decrypt($user['mpcode']);
$State = getStateName($user['State']);
$Country = getCountryName($user['Country']);
$billingname = stripdata($user['FirstName']).' '.stripdata($user['LastName']);
$billingaddress = stripdata($user['Address1']).'<br>'.stripdata($user['City']).', '.$State.' '.stripdata($user['Zip']).'<br>'.$Country;
$ShippingState = getStateName($user['ShippingState']);
$ShippingCountry = getCountryName($user['ShippingCountry']);
$shippingname = stripdata($user['ShippingFirstName']).' '.stripdata($user['ShippingLastName']);
$shippingaddress = stripdata($user['ShippingAddress1']).'<br>'.stripdata($user['ShippingCity']).', '.$ShippingState.' '.stripdata($user['ShippingZip']).'<br>'.$ShippingCountry;
$email = $user['Email'];
$phone = $user['Phone'];
$DateTime = getDateTime($user['DateTime']);
$afterdiscount = $cartObj->getpriceformat($finaltotal) - ($cartObj->getpriceformat($user['mpcode_discount']) + $cartObj->getpriceformat($user['misc_discount']));
$misc_discount = $cartObj->getpriceformat($user['misc_discount']);
} }
答案 0 :(得分:0)
在大多数服务器上,对于包含php页面的“脚本运行”,超时设置得相当低。错误500表示完成所有迭代花费的时间太长,160可能会超时。