问题描述
对于Ex-
如果用户在文本框中输入
bookno-101本总本-2
bookno - 101 totalbook - 2
receiptno-500总记录-2
receiptno - 500 totalrec - 2
优惠券-700总额-2
coupon - 700 totalcoup - 2
然后输出如下表所示.
在此表中,优惠券编号始终是唯一的.收据编号两次出现,每张收据都分配了两张优惠券.
对于Ex-
图书收据优惠券
101500-700
101 500 - 700
101500-701
101 500 - 701
101-501-702
101 - 501 - 702
101-501-703
101 - 501 - 703
102-502-704
102 - 502 - 704
102-502-705
102 - 502 - 705
102-503-706
102 - 503 - 706
102-503-707
102 - 503 - 707
现在是我第二次输入
bookcode = 800book_no2 = 802
bookcode = 800book_no2 = 802
收据代码= 1600Temp_receipt = 1602
receiptcode = 1600Temp_receipt = 1602
优惠券代码= 1800
Temp_coupon = 1802
couponcode = 1800
Temp_coupon = 1802
然后生成如下所示的输出
then generate output like below
图书收据优惠券801 -1601 1801801 -1601 -1802801 -1602 -1803801 -1602 -1804802 -1603 -1805802 -1603 -1806802 -1604 -1807802 -1604 -1808
book receipt coupon801 -1601 1801801 -1601 -1802801 -1602 -1803801 -1602 -1804802 -1603 -1805802 -1603 -1806802 -1604 -1807802 -1604 -1808
我尝试下面的代码,但工作不正常.
i try below code but not working properly.
<?php
if(isset($_POST['save']))
{
$bookcode = $_POST['bookcode'];
$book_no2 = $_POST['book_no2'];
$receiptcode = $_POST['receiptcode'];
$receipt_no = $_POST['receipt_no'];
$couponcode = $_POST['couponcode'];
$coupon = $_POST['coupon'];
$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;
}
$Pric = "";
$loopCount = 0;
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;
}
$value = $loopCount++ + 1;
$code = '- mths';
$Pric=$value.$code;
$insertrow = $database->insertRow("INSERT INTO scheme_master (book_no2,receipt_no,coupon)
VALUES (:book_no2,:receipt_no,:coupon)",
array(':receipt_no'=>$top,':book_no2'=>$row1,':coupon'=>$coup));
}
}
}
$_SESSION['message'] = "Books Created Successfully";
}
?>
我正在得到如下表所示的输出...
图书收据优惠券
101-501 -701
101 - 501 -701
101-502 -702
101 - 502 -702
102-501 -701
102 - 501 -701
102-502 -702
102 - 502 -702
推荐答案
每次使用循环时,它都会重置回输入的值(例如coupon_no)
Each time you use a loop it resets back to the entered value (e.g., coupon_no)
您应使用bookno
,couponno
和receiptno
的值作为起点,并使用totalbook
,totalcoup
和totalrec
的值作为循环标准.随手增加数字:
You should use the values for bookno
, couponno
and receiptno
as starting points and the values for totalbook
, totalcoup
and totalrec
as the loop criteria. Increment the numbers as you go:
<?php
$bookno= $_POST['bookcode'];
$totalbook= $_POST['book_no2'];
$receiptno = $_POST['receiptcode'];
$totalrec= $_POST['receipt_no'];
$couponno= $_POST['couponcode'];
$totalcoup= $_POST['coupon'];
for ($book_counter=1; $book_counter<=$totalbook; $book_counter++)
{
for($rec_counter=1; $rec_counter<=$totalrec; $rec_counter++)
{
for($coup_counter=1; $coup_counter<=$totalcoup; $coup_counter++)
{
$insertrow = $database->insertRow(
"INSERT INTO scheme_master (book_no2,receipt_no,coupon) VALUES (:book_no2,:receipt_no,:coupon)",
array(':receipt_no'=>$receiptno,':book_no2'=>$bookno,':coupon'=>$couponno));
$couponno++;
}
$receiptno++;
}
$bookno++;
}
?>
注意事项(此功能尚未经过测试,但可以让您走上正确的道路)
NB This has not been tested but it should set you on the right path
这篇关于php代码使用自定义代码生成多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!