-1

I have an array with around 300 or 400 elements. I am using a foreach loop to process every array element, like this:

$cnt=0;
foreach($resIds as $resId)
{
  $cnt++;
  //my queries and other code 

} 

My problem is that the above code causes an internal server error.

If I put one condition in the loop it's working fine for first 160 loops, like:

$cnt=0;
    foreach($resIds as $resId)
    {
      $cnt++;
      if($cnt<=160)
      {
        //my queries and other code 
      }

    } 

If I set $cnt variable to 161 it will give error of Internal Server Error.

Can anyone help me with this?

here is the Code

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']);

} }

4

1 回答 1

0

在大多数服务器上,包括 php 页面的“正在运行的脚本”的超时设置非常低。错误 500 可能表示完成所有迭代花费的时间太长,并且 160 可能会达到您的超时。

于 2013-04-23T09:47:32.443 回答