you need to transfer a two-dimensional array from php to js
array formation
while($res2 = mysql_fetch_array($res)) { $count++; $arr[] = $res2; } Js function
function ShowTable(ind) { //$("[name = "+ind+"]").css('display', 'block'); alert(ind['index']); $("tr[name = "+ind['index']+"]").after( '<tr name="$tId" onclick="ShowTable($tId)">'+ '<td><input type = "checkbox" name = "$tId"></input>'+ '<td></td>'+ '<td><?=$arr[$i]['index']?></td>'+ '<td>$tSource</td>'+ '<td>$tMessage</td>'+ '<td>$tDate</td>'+ '<td>s</td>'+ '<td><button type="button" class="btn btn-danger btn-xs active">Stop</button></td>'+ '</tr>'); } I'm trying to convey
<? for($i = 0; $i < $count; $i++) { for($j = 0; $j < $count; $j++) { if($arr[$j]['index'] == $index1) $indexCount++; else $index1 = $arr[$j]['index']; } if($arr[$i]['index'] != $index) { ?> <tr name="<?=$arr[$i]['index']?>" onclick="ShowTable(<?=$arr[$i]?>)"> <td><input type = "checkbox" name = "<?=$arr[$i]['index']?>"></input> <td><?=$arr[$i]['index']?></td> <td><?=$arr[$i]['source']?></td> <td><?=$arr[$i]['message']?></td> <td><?=date('Ymd H:i:s', $arr[$i]['timeToSend'])?></td> <td><?=$indexCount?></td> <td><button type="button" class="btn btn-danger btn-xs active" onclick="StopSend(<?=$arr[$i]['index']?>)">Stop</button></td> </tr> <? } $index = $arr[$i]['index']; } ?> on exit I get the value ind['index'] undefined, what am I doing wrong?
<?=$arr[$i]['index']?>Pass<?=$arr[$i]?>. You are accessing a non-existent index in JS. You also have an error in the string'<td><?=$arr[$i]['index']?></td>'. With quotes trouble. Just in case, I remind you that php-code is not executed in JS. - VenZellonclick="ShowTable(<?=$arr[$i]?>)"But nothing comes of it ... and then with quotes I’ll figure it out, you first need to get an alert to get something sensible - Anton Burak