我在MySQL中有一個表格來包含用戶創建的反機器人問題。但是,在安裝表格時,我想事先插入一些默認的反機器人問題。我想出了下面的代碼,但我不確定如何將它放入正確的語法。基本上,我創建了兩個數組(一個用於問題,另一個用於答案,按照各自的順序排列),並且想要使用foreach()或者while()函數循環訪問每個問題和答案。如何使用php將多行數據插入到mysql表中?
這裏是我的代碼:
$questions = array(
"question1" => "What is 2+6?",
"question2" => "What color is the sky?",
"question3" => "What number is betwee 6 and 8?",
"question4" => "How many letters are there in the English alphabet?",
"question5" => "How many hours are there in a day?",
"question6" => "Are you a human or a bot?"
);
$answers = array(
"answer1" => "8",
"answer2" => "blue",
"answer3" => "7",
"answer4" => "26",
"answer5" => "24",
"answer6" => "human"
);
$x = 0;
foreach ($question[$x]) {
$sql = "INSERT INTO
administrator_instructions
(question, question_naswer)
VALUES
('" . $question[$x] . "','" . $answer[$x] . "')";
$x++;
}
謝謝,那工作 – 2010-12-02 06:39:50
@ Qlidnaque:歡迎你 – RageZ 2010-12-02 06:40:52