We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36571
    • 145 Posts
    Hey all,

    I am attempting to output a list of products in a cart, and then send them by email using eform, as well as writing them to the db using eform2db. However, I am having a bit of trouble getting eform2db to output all the items.

    This is what I have right now
    $cart = $_SESSION['cart'];
    	if ($cart) {
    		$items = explode(',',$cart);
    }
    
    
    foreach ($items as $id) {
    $fields['objid'] = $id;
    }


    Although this only outputs the final item in the cart. Is there an easy fix? Is there perhaps a better way to approach this?

    Any help would be greatly appreciated.

    Thanks.
      • 16278
      • 928 Posts
      I’m not familiar with eform2db, but if you need an array of IDs to process, you can do it like this:
      $cart = $_SESSION['cart'];
      	if ($cart) {
      		$items = explode(',',$cart);
      }
      
      
      foreach ($items as $id) {
      $fields['objid'][] = $id;
      }

      That is, you’ll be adding the individual IDs to the array $fields[’objid’] instead of overwriting the array element $fields[’objid’] on each pass through the loop as at present.
      wink KP
        • 36571
        • 145 Posts
        Thanks kp52.

        Solved the problem by simply dropping the snippet in a readonly textarea un my eform template. Quick and dirty, perhaps. But effective.

        Will almost certainly be using your solution for a couple of upcoming projects though.

        Cheers,
        Dan