Link to home
Create AccountLog in
PHP

PHP

--

Questions

--

Followers

Top Experts

Avatar of David Schure
David Schure

Second List box not Populating
https://arise.plus/ADMIN/therapist-client-report.php
<!-- 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>

Open in new window

<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>    

Open in new window

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>'; 
    } 
} 
?>

Open in new window

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of David H.H.LeeDavid H.H.Lee🇲🇾

I didn't see your client_id field in your query?

$query = "SELECT tbl_client.client_name FROM tbl_client INNER JOIN ..."

change to

$query = "SELECT tbl_client.client_id,tbl_client.client_name FROM tbl_client INNER JOIN ..

Open in new window


 

Avatar of David SchureDavid Schure

ASKER

Good catch!  I added the client_id but still no populated listbox.  I ran the query in Navicat and it returns value...
"SELECT tbl_client.client_id,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";

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of David H.H.LeeDavid H.H.Lee🇲🇾

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

PHP

PHP

--

Questions

--

Followers

Top Experts

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.