I want to create a network graph using checkboxes. If I select 1 or more checkboxes then I click on the button, I want to draw network graph from the selected checkboxes. It's actually works, but if I select more than 1, it just prints 1 node, but if I select just 1, it's working perfectly. How can I solve this problem?
index.php
<td align="center"><input id="'.$row["id2"].'" class="checkboxes" type="checkbox" value="'.$row["id2"].'"</td>
<script>
$(document).ready(function(){
$('.relations').click(function(e){
e.preventDefault();
$("#dataModal3").modal("hide");
// Checkboxes
var insert=[];
$('.checkboxes').each(function(){
if($(this).is(":checked")){
insert.push($(this).val());
}
});
insert=insert.toString();
var data_id = $(this).attr("id");
$.ajax({
url:"nodes.php",
method:"post",
dataType: "json",
data:{data_id:data_id,insert:insert},
success:function(data){
$('#moreInfo').html(data);
$('#dataModal').modal("show");
var nodeDatas = new vis.DataSet();
nodeDatas = data;
$.ajax({
method:"post",
dataType: "json",
url: "edges.php",
data:{data_id:data_id},
success: function(data){
var edgeDatas = new vis.DataSet();
edgeDatas = data;
var myDiv = document.getElementById("moreInfo");
data={
nodes: nodeDatas,
edges: edgeDatas
};
var options = {
};
var network = new vis.Network(myDiv, data, options);
}
});
}
});
});
});
</script>
nodes.php
if(isset($_POST["insert"])){
$sql2=$conn->prepare("SELECT id, data
FROM table1
WHERE id=?
GROUP BY id");
$sql2 -> bind_param('i', $_POST['insert']);
$sql2 -> execute();
$result2 = $sql2 -> get_result();
$sql2 -> close();
while($row = mysqli_fetch_assoc($result2)){
$id2 = $row['id'];
$data = $row['data'];
$arr[] = array("id" => $id2,
"label" => $data);
}
}
Aucun commentaire:
Enregistrer un commentaire