I'm creating a page which will allow an admin to select a user from a drop down list, which populates from a database. When the person is selected, the info associated with that person will then be viewed on the page. I already have a select statement which selects all the info and the drop down menu is populating correctly. However, I'm unsure on how to get that selected user's info to display on the page once selected. Would I need to do an entirely different select statement and query which checks which customer was selected? Or would I need to delve into the AJAX world? If that's the case, how would I use AJAX and PHP together in the scope of this project?
<div id="view_form" class="view">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
<label for="viewCustomer">Select Customer</label>
<?php
echo "<select name='selectCust' id='selectCust'>";
echo "<option value=$name></option>";
while($row = mysqli_fetch_assoc($custResult)){
$name = "{$row['fName']} {$row['lName']}";
$acct = $row['acctNum'];
echo "<option>$name</option>";
}
echo "</select>";
echo "</fieldset>";
?>
</form>
</div>
This is definitely an AJAX situation. I'm not sure if you're using JQuery on this page, but that would help you a lot.
It would look something like this:
$("#selectCust").change(function(){
var selected = $("#selectCust").val();
$.ajax({
url: "backEnd.php",
data: {
'selected': selected
},
success: function(data) {
$( this ).addClass( "done" );
}
});
});
The database stuff would occur in backEnd.php
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.