Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3215036
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:07:51+00:00 2026-05-17T15:07:51+00:00

I have a Joomla website that I’ve written a custom shopping cart component for.

  • 0

I have a Joomla website that I’ve written a custom shopping cart component for. The user is basically purchasing codes we’re storing in our database – these are associated with a printed incentive card. When the user checks out, I need to grab a chunk of codes from the database (however many they’ve purchased), then loop through the list of codes and update other tables with information in my cart. The cart is stored as an array of arrays in a session variable, like this:

$cart = Array ( 
[0] => Array ( [TypeFlag] => S [qty] => 25 [denom] => 50  [totalPrice] =>  100 )
[1] => Array ( [TypeFlag] => V [qty] => 10 [denom] => 25  [totalPrice] => 25 ) 
[2] => Array ( [TypeFlag] => C [qty] => 100 [denom] => 25  [totalPrice] => 25 ) 
) 

where each internal array is one line item in the cart. It’s the qty that’s causing the problem; when they’re low there’s no problem running all the insert and update queries inside the loop. However, when the qty elements are high, I start getting memory allocation errors. This is understandable, as it’s basically running several queries hundreds of times. The issue is, a user could potentially order a thousand cards or more at a time (this is a corporate incentive program), so I need to be able to get all records inserted and updated, regardless of how big the qty is.

Here’s the relevant code:

First, the loop:

//loop through vouchers to create purchase records, update voucher records, create certificates
$rightNow = date("YmdHis");
foreach($vouchers as $voucher) {
    $VoucherID = $voucher['VoucherID'];
    $VoucherIDList .= $VoucherIDList ."," . $voucher['VoucherNbr'];
    //create purchase record            
    $purchData = array("CcAuthCode"=>$ccAuthCode,"VoucherID"=>$VoucherID,"PurchAmt"=>$realFinalTotal, "ShipHandFee"=>number_format($shippingCharge,2),  "PurchDT"=>$rightNow,  "AcctID"=>$accountIDs['UserAcctID'], "ShipAddrID"=>$accountIDs['MailingAcctID']);
    $purchID = $model->createPurchaseRecord($purchData);    

    //update voucher
    $model->updateVoucherInfo($VoucherID,$accountIDs['BillingAcctID'], $denom, $purchID,$message);
}

The actual queries are inside the createPurchaseRecord and updateVoucherInfo functions in the model:

function createPurchaseRecord($data){    
    $db =& JFactory::getDBO();
    $insFields = "";
    $valFields = "";

    foreach ($data as $f => $v){
        $insFields .= "," . $f;
        $valFields .= "," . $db->quote($v);
    }

    $insFields = substr($insFields,1);
    $valFields = substr($valFields,1);

    $query = "insert into arrc_PurchaseActivity ({$insFields}) values ({$valFields})";
    $db->setQuery($query);
    if (!$db->query()) error_log($db->stderr());

    return $db->insertid();
}

function updateVoucherInfo($voucherID,$billingAcctId, $balanceInit, $purchID, $certMessage) {
    //set ActivatedDT, BalanceInit
    $rightNow = date("YmdHis");
    $db =& JFactory::getDBO();
    $query = "UPDATE arrc_Voucher 
        set ActivatedDT=".$db->quote($rightNow).", BalanceInit=".$db->quote($balanceInit) . ", BalanceCurrent=".$db->quote($balanceInit).
    ", AcctID=".$db->quote($billingAcctId).", PurchActvtyID=".$db->quote($purchID) . ", certMessage=".$db->quote($certMessage)
    . " WHERE VoucherID=".$db->quote($voucherID);

    $db->setQuery($query);
    if (!$db->query()) error_log($db->stderr()); 
    $certificateNumber = $voucherID;
    return $certificateNumber;

}

Can anyone help me out? There has to be a way to make this more efficient; right now it’s throwing a memory error when I try to do any more than 30 or so at a time; given the requirement for 1,000+, this is a big deal. This is the error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71303153 bytes) in /var/www/html/mysite.com/components/com_arrcard/controllers/checkout.php on line 110

Line 110 is this line from the loop above:

   $VoucherIDList .= $VoucherIDList ."," . $voucher['VoucherNbr'];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:07:51+00:00Added an answer on May 17, 2026 at 3:07 pm
    $VoucherIDList .= $VoucherIDList ."," . $voucher['VoucherNbr'];
    

    You are doing this wrong. You concatenate the list to itself resulting in the variable growing exponentially.

    Correct way:

    $VoucherIDList .= "," . $voucher['VoucherNbr'];
    

    or

    $VoucherIDList = $VoucherIDList ."," . $voucher['VoucherNbr'];
    

    Regards,
    Alin

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a joomla website and I use community builder for user registration and
I have to redesign a website in joomla from HTML.Basically the HTML site is
I have a big Joomla website that was moved from .com to .eu domain.
I have a Joomla Website located at http://www.MikeSilvis.com , and upon going to the
I have a Joomla 1.0 website running on a shared host which I don't
i have a big Joomla 1.5 Problem. I'll create my own Gallery Component/PlugIn and
I have a website developed in php and Joomla.Now i want to add a
We have a website based on Joomla! in the joomla directory, there are many
I have a website developed in Joomla. I want to add my gtalk id
I have a joomla website with the virtuemart module. What I have are images

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.