I have this PHP code to select data from a database:
<?php
include './database_connect.php';
$ppid=$_POST['selectPatientID'];
$query="SELECT * FROM patient WHERE p_Id='$ppid'";
$result= mysqli_query($conn, $query);
while($row= mysqli_fetch_array($result)){
echo ($row['p_fname']);
echo ' ';
echo ($row['p_lname']);
}
?>
But I need to get the p_fname
and p_lname
values separately. Is there anything I could do to achieve this?
This is my jQuery:
<script>
$(document).ready(function () {
$('#selectPatientID').on('change', function (event) {
event.preventDefault();
// alert("Hi");
$.ajax({
url: "UDPatient.php",
type: 'POST',
data: {selectPatientID: $('#selectPatientID').val()},
dataType: 'html',
success: function (result) {
$('#patientName').val(result); //in here, how can I get the p_fname and p_lname separetely and put them in two different input fields?
}
});
});
});
</script>