<!-- Therapist dropdown --> <?php $result = mysqli_query($con, "SELECT tbl_therapist.therapist_id, tbl_therapist.therapist_name FROM tbl_therapist ORDER BY therapist_name ASC;"); ?> <label><strong>THERAPIST</strong></label><BR> <select name="therapist" id="therapist" size="10"> <?php while ($row = mysqli_fetch_array($result)) { printf("<option value='%s'>%s</option>", $row['therapist_id'], $row['therapist_name']); } ?> </select> <!-- Client dropdown --> <select id="client"> <option value="">Select Therapist first</option> </select> <!-- Session dropdown --> <select id="session"> <option value="">Select Client first</option> </select>
<script> $(document).ready(function(){ $('#therapist').on('change', function(){ var therapistID = $(this).val(); if(therapistID){ $.ajax({ type:'POST', url:'ajaxData.php', data:'therapist_id='+therapistID, success:function(html){ $('#client').html(html); $('#session').html('<option value="">Select Therapist first</option>'); } }); }else{ $('#client').html('<option value="">Select Therapist first</option>'); $('#session').html('<option value="">Select Client first</option>'); } }); $('#therapist').on('change', function(){ var therapistID = $(this).val(); if(therapistID){ $.ajax({ type:'POST', url:'ajaxData.php', data:'therapist_id='+clientID, success:function(html){ $('#session').html(html); } }); }else{ $('#session').html('<option value="">Select Client first</option>'); } }); }); </script>ajaxData.php page
<?php // Include the database config file include_once 'includes/pdo_connection.php'; if(!empty($_POST["therapist_id"])){ // Fetch state data based on the specific country $query = "SELECT tbl_client.client_name FROM tbl_client INNER JOIN tbl_therapist_client ON tbl_therapist_client.client_id=tbl_client.client_id WHERE tbl_therapist_client.therapist_id = ".$_POST['therapist_id']." ORDER BY tbl_client.client_name ASC"; $result = $db->query($query); // Generate HTML of state options list if($result->num_rows > 0){ echo '<option value="">Select Client</option>'; while($row = $result->fetch_assoc()){ echo '<option value="'.$row['client_id'].'">'.$row['client_name'].'</option>'; } }else{ echo '<option value="">Client not available</option>'; } }elseif(!empty($_POST["client_id"])){ // Fetch city data based on the specific state $query = "SELECT * FROM tbl_session WHERE client_id = ".$_POST['client_id']." ORDER BY client_name ASC"; $result = $db->query($query); // Generate HTML of city options list if($result->num_rows > 0){ echo '<option value="">Select Session</option>'; while($row = $result->fetch_assoc()){ echo '<option value="'.$row['session_id'].'">'.$row['session_date'].'</option>'; } }else{ echo '<option value="">Session not available</option>'; } } ?>
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.