php代码从for循环生成备用no

I am generating book ,receipt ,coupon and price.

I used for loop to generate all the series.

Every forloop gets custom code and total value from textbox to generate all data.

Now my rerquirement is how to generate price in each coupon.

for ex- In below table ,Every receiptcode has 2 unique couponcode.Ok,

receipt couponcode

701 = 501,502

702 = 503,504

703 = 505,506 OK.

Now I need to also insert alternate price with each coupon like below example

for ex -

couponcode price

501 -- 1

502 -- 2

503 -- 1

504 -- 2

505 -- 1

506 -- 2

below is my code to generate all data using forlloop.

plz suggest me how to generate alternate price with each couponcode.

 <?php
    if(isset($_POST['save']))
        {       
                    $city = $_POST['city'];                 
                    $scheme_name = $_POST['scheme_name'];
                    $amount = $_POST['amount'];

                    $bookcode = $_POST['bookcode'];             
                    $book_no2 = $_POST['book_no2']; 

                    $receiptcode = $_POST['receiptcode'];
                    $receipt_no = $_POST['receipt_no'];                     
                    $couponcode = $_POST['couponcode'];                         
                    $coupon = $_POST['coupon'];                         
                    $created = date("Y-m-d H:i:s");             


                    $Temp_receipt = $receiptcode + $receipt_no;                 
                    $Temp_coupon = $couponcode + $coupon;

                    for($row1=$bookcode+1;$row1<=$bookcode+$book_no2;$row1++)
                        {   

                        for($row=$receiptcode+1;$row<=$Temp_receipt;$row++)
                            {

                                $query = $database->getRow("SELECT MAX(receipt_no) AS max1 FROM scheme_master;");
                                    if($query['max1']=='')
                                    {                           
                                        $largestNumber = $receiptcode;
                                        $top = $largestNumber + 1;
                                    }
                                    else
                                    {
                                        $largestNumber = $query['max1'];
                                        $top = $largestNumber + 1;  
                                    }       

                                    for($row2=$couponcode+1;$row2<=$Temp_coupon;$row2++)
                                    {                                   
                                        $query = $database->getRow("SELECT MAX(coupon) AS max2 FROM scheme_master;");
                                        if($query['max2']=='')
                                        {                           
                                            $largestcoupon = $couponcode;
                                            $coup = $largestcoupon + 1;                                 
                                        }
                                        else
                                        {
                                            $largestcoupon = $query['max2'];
                                            $coup = $largestcoupon + 1; 
                                        }   



  $insertrow = $database->insertRow("INSERT INTO scheme_master (price,amount,scheme_name,city,book_no2,receipt_no,coupon,created)
VALUES (:price,:amount,:scheme_name,:city,:book_no2,:receipt_no,:coupon,:created)", 
array(':price'=>$pric,':amount'=>$amount,':scheme_name'=>$scheme_name,':city'=>$city,':receipt_no'=>$top,':book_no2'=>$row1,':coupon'=>$coup,':created'=>$created));

                                }

                        }
                    }
                        $_SESSION['message'] = "Books Created Successfully";                        
        }       

    ?>

If I understand you correctly, you want to alternate between 1 and 2 in each iteration of your for-loop? That could be achieved like this:

First initialize $loopCount = 0

Then, in the loop, you do something like this:

if($loopCount++ % 2 == 0) {
    echo "1";
} else {
    echo "2";
}

Alternative:

echo $loopCount++ % 2 + 1;

It will check whether $loopCount will be even or uneven, and generate output accordingly.

That's how it works. It's up to you to integrate that in your code.