2

I'm having an issue producing this array multiple times upon how many coupons purchased.

Now it looks like

$coupon_array = array(
    'user_id'=>$_POST["user_id"],
    'mergent_id'=>$_POST["merchant_id"],
    'deals_id'=>$_POST["deal_id"],
    'order_id'=>$order_id,
    'secret'=>$secret,
    'expire_time'=>$time,
    'create_time'=>$time,
    'status'=>1
   );

   $this->common_model->insertData('coupon', $coupon_array);

But i have a post value such as:

"quantity"=>$_POST["quantity"]

and i would like to produce this X times. Example:

$quantity x $this->common_model->insertData('coupon', $coupon_array);

Sorry for my english, and i hope i explain this so it's understandable... ;)

Another one! when we insert the coupons they all have the same md5($secret), is it possible to have that also with all the different code...

 $secret = md5($secret);


   $coupon_array = array(
    'user_id'=>$_POST["user_id"],
    'mergent_id'=>$_POST["merchant_id"],
    'deals_id'=>$_POST["deal_id"],
    'order_id'=>$order_id,
    'secret'=>$secret,
    'expire_time'=>$time,
    'create_time'=>$time,
    'status'=>1
   );

2 Answers 2

3

Well, if I understand what you want, you can use for, but that's obvious:

for($i=0; $i<$this->input->post('quantity');$i++) {
    $coupon_array['secret'] = md5($coupon_array['secret'].$i);
    $this->common_model->insertData('coupon', $coupon_array);
}

Also, never use $_POST["..."] in CodeIgniter, use only $this->input->post('...') as it escapes properly. More info about input class can be found here.

Sign up to request clarification or add additional context in comments.

4 Comments

this should work but I kind of wonder why quantity isn't just a database field
@JohnB I wondered myself for a bit, but then understood that maybe every element should be processed separately, like he has status field, a customer buys 10 elements, 5 of which are processed and have status changed, while 5 remain with original status. It might not be the best design, but it's easier to maintain that way :)
Another issue, we have a $secret code generated for each coupon via md5() but now it's adding all coupons with the same md5 ;) See above..
@HafsteinnMárMásson I have updated my answer, now they will have different $secret fields
0
for ($i=0; $i<$quanity; $i++) {
       $this->common_model->insertData('coupon', $coupon_array);
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.