0

I need to generate no in serial order starts from custom code. If user want to print two book with 3 receipt in each book and 2 coupon in each receipt.

  • user enter book code and total book

  • user enter receipt code and total receipt

  • user enter coupon code and total coupon

User input in textbox like:

bookno   - 101
totalbook    -  2

receiptno  - 500
totalrec      -  2

coupon     -  700
totalcoup     -   2

then output comes like below table.

In this table, coupon no are always unique.and receipt no comes twice because each receipt has two coupon alloted.

Please suggest me how generate below output using for loop and insert every row in database.

book   receipt     coupon

101     500        -   700

101     500        -   701

101  -   501       -    702

101  -   501        -   703

102   -  502        -   704

102  -   502         -  705

102   -  503        -   706

102   -  503        -   707

i try below code but not working properly.

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

                $receiptno = $_POST['receiptcode'];
                $totalrec= $_POST['receipt_no'];                        
                $couponno= $_POST['couponcode'];                            
                $totalcoup= $_POST['coupon'];   


for($row1=$bookno;$row1<=$bookno+$totalbook;$row1++)
                    {   

                    for($row=$receiptno;$row<=$receiptno+$totalrec;$row++)
                        {

                                for($row2=$couponno;$row2<=$couponno+$totalcoup;$row2++)
                                {   

$insertrow = $database->insertRow("INSERT INTO scheme_master (book_no2,receipt_no,coupon)
VALUES (:book_no2,:receipt_no,:coupon)", 
array(':receipt_no'=>$row,':book_no2'=>$row1,':coupon'=>$row2));

                            }

                    }
                }
1

1 Answer 1

2

Your question is EXACTLY the same as this one from Ashok Awachat. You both seem to be submitting questions to StackOverflow pretty regularly to get someone else to do your (I assume) college work.

As I said before in an earlier answer, go back to first principles:

  1. If you're having problems running SQL queries through PHP, try the query on the database directly with hard-coded values

  2. If the SQL works correctly on the database, try it from PHP with hard-coded values again

  3. Don't re-invent the wheel. You're using methods which take a query and a set of parameters. If you typed out the full PHP for this, the overhead is negligible but readability of your code will increase.

  4. Progressively add debugging code to your app so that you can check what is happening at each stage. Once you're happy that one part is working, add debugging to the next part. (Debugging in this instance is logging of values and errors)

  5. Work slowly and methodically. Don't try to get everything done in one go. Start small and go from there.

With regards to StackOverflow, you need to consider the following:

  1. The questions you are submitting are pretty rudimentary and relate to basic things like not understanding variable scope. Therefore, buy some books on PHP, SQL and HTML which you can refer to. Bookmark the documentation pages for the systems you are using. Search the web for tutorials etc

  2. Submit as much information with your questions as possible. By this, I mean give the code you have tried, what errors you are getting ("it doesn't work" is not acceptable) etc. if someone asks for output from something, supply it.

  3. Don't treat StackOverflow members as a vast repository of people willing to do your project for you. Everyone here are answering questions out of the goodness of their heart. They don't have to be here. I would guess that the vast majority of people answering questions have jobs which pay good money.

  4. Once a question is answered, don't then go back and change the question to ask another one (Ashok did this). Also, don't delete comments if you do this as it removes context from the question. Start a new question off. If you're unable to do this as you've hit a limit for questions per day (I don't know if this is possible), then this should be a warning signal to yourselves that you are taking the easy way out

If you're going to be a developer then you need to know how to bug-hunt. Asking a question on StackOverflow every time you have a problem is not teaching you anything

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

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.