Hi!
I have problem that i fail to find solution for and im looking for some help from you as im hopelessly struggling for answers.
So i have a HTML table and some cells are filled with id-d div-s. The problem is only the first id-d cell is filled with data.
Im calling a JS function that is linked with ajax. Im calling this function in for loop, but function runs only once.
for loop:
echo "<script language='JavaScript' type='text/javascript'> ";
for($b=0; $b<10; $b++){
echo "ajax_fill(".$b.",".$IDarr[$b].");n";
}
echo "</script>";
JS function:
function ajax_fill(nr,id){
var hr = new XMLHttpRequest();
var url = "table_score_filler.php";
var post_vars = "nr_fill="+nr+"&id_fill="+id;
var skoor_str1 = "skoor"+nr;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById(skoor_str1).innerHTML = return_data;
}
}
hr.send(post_vars);
document.getElementById("status_fill").innerHTML = "fill score task: processing...";
}
And table_score_filler.php content:
<?php
$id = $_POST['id_fill'];
$nr = $_POST['nr_fill'];
//echo $id." ".$nr;
//alert($nr);
$connect = mysql_connect("localhost","rstudent","student") ;
mysql_select_db("reddit", $connect) or die("Ei leidnud andmebaasi at table_processor.php code.");
$query = mysql_query("
SELECT skoor FROM t104557_links WHERE id='$id';") or die("table score fill problem!");
//$result = mysql_query ($query);
$row = mysql_fetch_array($query);
$skoor = $row[0];
echo $nr." ".$skoor; //."fill fail <br />"
?>
Thank you in advance!