php代码创建动态行并插入数据库 [英] php code to create dynamic rows and insert in database
问题描述
我需要从自定义代码开始不按顺序生成任何内容.如果用户要打印两本书,每本书有3张收据,每张收据中有2张优惠券.
-
用户输入书籍代码和总书籍
-
用户输入收据代码和总收据
-
用户输入优惠券代码和总优惠券
用户在文本框中的输入,例如:
bookno - 101
totalbook - 2
receiptno - 500
totalrec - 2
coupon - 700
totalcoup - 2
然后输出如下表所示.
在此表中,优惠券编号始终是唯一的.由于每个收据都分配了两个优惠券,因此收据编号会出现两次.
请建议我如何使用for循环生成下面的输出并在数据库中插入每一行.
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
我尝试下面的代码,但工作不正常.
$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));
}
}
}
您的问题与 可接受的)等等.如果有人要求提供某些东西,请提供它. /p>
不要将StackOverflow成员视为愿意为您做项目的人们的庞大仓库.这里的每个人都在发自内心地回答问题.他们不必在这里.我猜想绝大多数回答问题的人都有能赚钱的工作. 一旦回答了一个问题,请不要再回去更改问题以询问另一个问题(Ashok做到了).另外,如果要删除注释,因为它会从问题中删除上下文,因此请不要删除注释.开始一个新的问题.如果您无法做到这一点,因为您每天都遇到问题的限制(我不知道是否有可能),那么这应该向您自己发出警告,警告您正在采取简便的出路方式 如果您要成为一名开发人员,那么您需要知道如何寻找错误.每次遇到问题时,都在StackOverflow上提问是没有教给您任何东西 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: 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. i try below code but not working properly.
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: If you're having problems running SQL queries through PHP, try the query on the database directly with hard-coded values If the SQL works correctly on the database, try it from PHP with hard-coded values again 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. 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) 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: 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 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. 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. 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 这篇关于php代码创建动态行并插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
bookno - 101
totalbook - 2
receiptno - 500
totalrec - 2
coupon - 700
totalcoup - 2
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
$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));
}
}
}