UPDATE! ADDING PHP code
<?php
$tq_array = array();
$c_array = array();
$o1_array = array();
$o2_array = array();
$o3_array = array();
$questions = mysql_query("SELECT * FROM test WHERE exam_code = '$exam'");
while($row = mysql_fetch_assoc($questions)){
$tq_array[] = $row['test_question'];
$c_array[]= $row['correct_answer'];
$o1_array[] = $row['option_1'];
$o2_array[] = $row['option_2'];
$o3_array[] = $row['option_3'];
}
$tq_json = json_encode($tq_array);
$c_json = json_encode($c_array);
$o1_json = json_encode($o1_array);
$o2_json = json_encode($o2_array);
$o3_json = json_encode($o3_array);
?>
我的問題是我想將這個轉換後的javascript數組(從php數組)添加到另一個存儲。在單個javascript數組中添加很多javascript數組
var questioner = JSON.parse('<?= $tq_json; ?>');
var correct_ans = JSON.parse('<?= $c_json; ?>');
var option1 = JSON.parse('<?= $o1_json; ?>');
var option2 = JSON.parse('<?= $o2_json; ?>');
var option3 = JSON.parse('<?= $o3_json; ?>');
這就是我要添加代碼
var i = 0
for(i = 0; i <= obj1.length;i++){
var questions = [
[ /* this is the one that fix the counting of the questioners*/],
[[obj1[i], obj2[i], obj3[i], obj4[i], obj5[i]],"false",1],
],
sec=20,
A;
}
我嘗試循環使用循環,但它沒有工作的存儲。
我喜歡出現像這樣()
var questions = [
[ /* this is the one that fix the questioner */],
[[obj1[i], obj1[i], obj1[i], obj1[i], obj1[i]],"false",1],
[[obj2[i], obj2[i], obj2[i], obj2[i], obj2[i]],"false",1],
[[obj3[i], obj3[i], obj4[i], obj3[i], obj3[i]],"false",1],
So on ....
],
sec=20,
A;
謝謝!
在你的代碼示例你的變量不匹配了,我們不知道的PHP陣列的內容。這使得很難確切地看到你的意思。你能否更新這個。 – Mouser