동적으로 생성되는 여러 텍스트 상자가 있습니다. 상자의 수는 매번 다를 수 있습니다. 자바 스크립트 (box1, box2 등)에서 생성 된 변수의 수를 백엔드의 테이블에서 호출 된 행 수와 어떻게 일치 시키나요? 예 : $ query의 결과로 2 행만 있으면 두 개의 자바 스크립트 변수 (box1 및 box2) 만 있어야합니다. 동시에 올바른 번호에 해당하는 올바른 URL을 동적으로 생성하려면 어떻게해야합니까?php와 javascript를 사용하여 동적으로 생성 된 변수의 수를 늘리려면 어떻게해야합니까?
$query = "SELECT * FROM `sessionid` WHERE `sessionid` = '$session' ";
$result = mysql_query($query) or die(mysql_error());
echo '<table class="table"><tbody>';
$subtotal = 0;
$i=1;
while($row = mysql_fetch_assoc($result)) {
echo '<tr><td></td><td><h3>' . $row['title'] . '</h3></td><td>' . $row['options'] . '</td><td><div class="span3 offset1"><input type="text" id="box' . $i . '"value="' . $row['qt'] . '" class="span1"> <input type="button" class="btn" value = "Refresh" onclick="ajaxFunction()" /> <h4> $' . $row['price'] . '<div id="ajaxDiv">Your result will display here</div></h4></td></tr>';
$i++;
$prodtotal= $row['qt'] * $row['price'];
$subtotal= round($subtotal+ $prodtotal, 2);
$_SESSION['subtotal']=$subtotal;
}
echo '</form></tbody></table>';
//javascript later on
var box1 = document.getElementById('box1').value;
var box2 = document.getElementById('box2').value;
var box3 = document.getElementById('box3').value;
var box4 = document.getElementById('box4').value;
var queryString = "?box1=" + box1 + "&box2=" + box2 + "&box3=" + box3 + "&box4=" + box4;