I have 4 DIV which I want the First DIV to open the second on-click of it, the Second should open the Third DIV on-click of it and the Third DIV should open the Fourth DIV on-click of it. I used collapse to do this and at every point of clicking each of the DIV, I used AJAX to parse an ID to the next DIV that will be used to query the database to get lists of value.
Issues: 1 - When I click on the first DIV it doesn't collapse to show the next DIV but if I remove the data-toggle="collapse" data-target="#project_id_parse" from the First DIV and remove class="collapse" from the Second DIV it displays all the 4 DIV without clicking it.
2 - After removing the class="collapse" and data-toggle="collapse" data-target="#project_id_parse" and I click on the First DIV to parse the ID with AJAX it parses the ID to the Second DIV but when I click on the Second DIV to parse the ID to the Third DIV, the Second DIV ID affect all other DIV's instead of just parsing ID to the specific DIV.
Below is my code:
<?php
$query_active = "SELECT * FROM `table`";
$result_active = mysqli_query($connLocal, $query_active);
if(mysqli_num_rows($result_active)){
$active_numbering=0;
while($row_active = mysqli_fetch_assoc($result_active)){
$active_numbering++;
$project_id = $row_active['project_id'];
$project_name = $row_active['project_name'];
$project_type = $row_active['project_type'];
?>
<script>
$("#project_id_parse").click(function(e) {
e.preventDefault(); // <-------stop the def behavior here.
var id = this.firstElementChild.href.split('=').pop(); // extract the id here
$.ajax({
type: "get",
url: "project_list.php",
data: {id:project_id}, // now pass it here
success: function(data) {
$('#process_toggle').html(data); //copy and paste for your special case
}
});
});
</script>
<div id="project_id_parse" data-toggle="collapse" data-target="#project_id_parse" ><a href="project_list.php?id=<?=$project_id; ?>" ><?=$project_name; ?></a></div>
<div class="td"><?=$project_type; ?></div>
<?php
}
}
?>
<!----------------------- First DIV ends -------------------------------------->
<div id="process_toggle" class="collapse">
<?php
$project_id = $_GET["project_id"];
$query_process = " SELECT * FROM `table` WHERE project_id = '".$project_id."' " ;
$result_process = mysqli_query($connLocal, $query_process);
if(mysqli_num_rows($result_process)){
$NO=0;
while($row_process = mysqli_fetch_assoc($result_process)){
$NO++;
$name = $row_process['process_name'];
$process_id = $row_process['process_id'];
?>
<script type="text/javascript">
$("#process_id_parse").click(function(e) {
e.preventDefault(); // <-------stop the def behavior here.
var id = this.firstElementChild.href.split('=').pop(); // extract the id here
$.ajax({
type: "get",
url: "project_list.php",
data: {id:id}, // now pass it here
success: function(data) {
$('#activities_toggle').html(data); //copy and paste for your special case
}
});
});
</script>
<div id="process_id_parse"><a href="project_list.php?id=<?=$process_id; ?>"><?=$name?></a></div>
<?php
}
}
?>
<!------------------- the Second DIV ends --------------------------->
<div id="activities_toggle" class="content">
<?php
$process_id = $_GET["id"];
$query_activities = " SELECT * FROM `table` WHERE process_id = '".$process_id."' " ;
$result_activities = mysqli_query($connLocal, $query_activities);
if(mysqli_num_rows($result_activities)){
$NO=0;
while($row_activities = mysqli_fetch_assoc($result_activities)){
$NO++;
$name = $row_activities['activities_name'];
$activities_id = $row_activities['activities_id'];
?>
<script>
$("#activities_id_parse").click(function(e) {
e.preventDefault(); // <-------stop the def behavior here.
var id = this.firstElementChild.href.split('=').pop(); // extract the id here
$.ajax({
type: "get",
url: "project_list.php",
data: {id:id}, // now pass it here
success: function(data) {
$('#task_toggle').html(data); //copy and paste for your special case
}
});
});
</script>
<div id="activities_id_parse"><a href="project_list.php?id=<?=$activities_id; ?>"><?=$name?></a>
<?php
}
}
?>
<!------ Third DIVs ends -------------------->
<div id="task_toggle" class="collapse">
<?php
$activities_id = $_GET["id"];
$query_activities = " SELECT * FROM `table` WHERE activities_id = '".$activities_id."' " ;
$result_activities = mysqli_query($connLocal, $query_activities);
if(mysqli_num_rows($result_activities)){
$NO=0;
while($row_activities = mysqli_fetch_assoc($result_activities)){
$NO++;
$name = $row_activities['task_name'];
$task_id = $row_activities['task_id'];
?>
<div class="td"><?=$name?></div>
<?php
}
}
?>