我需要幫助弄清楚這一點。我需要運行MYSQLI INSERT sevral times并插入數(shù)據(jù)表單數(shù)組。我從一個表單中獲取數(shù)據(jù),其中包含兩個動態(tài)值(一個日期跨度)和一個來自最終用戶輸入的數(shù)字。我需要將其插入到數(shù)據(jù)庫中的表中。來自 secound 數(shù)組的數(shù)據(jù)需要在第一個數(shù)組中的所有日期插入。第一個數(shù)組 ( [0] => 2020/01/26 [1] => 2020/01/27 [2] => 2020/01/28 [3] )第二個數(shù)組數(shù)組 ( [0] => 1 [1] => 2 [2] => 3 [3] => )這是我希望插入到數(shù)據(jù)庫中的內(nèi)容:INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/26,1)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/26,2)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/26,3)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/27,1)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/27,2)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/27,3)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/28,1)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/28,2)INSERT INTO MYTABLE ('bookingdate', 'squarenumber',) VALUES (2020/01/28,3)任何人都可以幫我嗎?這對我來說有點困難...FORM <div id="massbooking-form-wrapper"> <div class="massbooking-form-select-squares-wrapper"> <h2>V?lj rutor p? omr?de:<br> <?php echo getAreaname($link, $sq_areas_id); ?></h2> <br><br> <form name="booking_form" id="booking_form" action="<?php echo $bookingHomeUrl;?>/modules/bookings/process-massbooking.php" method="post"> <div class="form-group" > <label>Startdatum<label> <input type="text" disabled name="booking_from_date_to_post" class="form-control" value="<?php echo $booking_from_date?>"> </div> </div> </form> </div> </div>
1 回答

慕運維8079593
TA貢獻1876條經(jīng)驗 獲得超5個贊
你還沒有真正解釋你有什么問題。您顯示的SQL不是正確的語法,因此我假設您正在為正確的SQL語法而苦苦掙扎。為此,MySQLi中的插入語句并不困難,您所要做的就是循環(huán)使用兩個數(shù)組并為每個值執(zhí)行語句。
$stmt = $mysqli->prepare('INSERT INTO MYTABLE (bookingdate, squarenumber) VALUES(?,?)');
$stmt->bind_param('ss', $bookingdate, $squarenumber);
foreach ($array1 as $bookingdate) {
foreach ($array2 as $squarenumber) {
$stmt->execute();
}
}
- 1 回答
- 0 關注
- 102 瀏覽
添加回答
舉報
0/150
提交
取消