How can i get the selected value from nationality_id to check query in book_id query. So I can find where is the country.
My selection got Nationality, Book and country. I want user to select nationality display book. And user select Book display for country. But my country will base on Nationality and book for display the data.
Appreciate anyone if can help me. My SQL got the result from what i need, just need help in correct the script
PHP script : nationality id
if(!empty($_POST['nationality_id'])) {
$query = "SELECT nationality.nationalities, book_type.book ";
$query .= "FROM info ";
$query .= "JOIN nationality ON nationality.id = info.nationality_id ";
$query .= "JOIN book_type ON book_type.id = info.book_type_id ";
$query .= "WHERE nationality.nationalities LIKE '{$_POST['nationality_id']}' ";
$query .= "GROUP BY book_type.book ";
$query .= "ORDER BY book_type.book DESC ";
$check_nationality = mysqli_query($db_connection, $query);
// Generate HTML of nationality options list
if($check_nationality->num_rows > 0){
echo '<option value="">Please Select Your Book</option>';
while($row = $check_nationality->fetch_assoc()){
echo '<option value="'.$row['book'].'">'.$row['book'].'</option>';
}
}
}
For display book without any problem : When i try to key in:
AND nationality.natioalities LIKE '{$_POST['nationality_id']}
My selection function did not work any more.
PHP script : book id
if(!empty($_POST['book_id'])) {
$query = "SELECT nationality.nationalities, book_type.book, region.region, country.country ";
$query .= "FROM info ";
$query .= "JOIN nationality ON nationality.id = info.nationality_id ";
$query .= "JOIN book_type ON book_type.id = book.book_type_id ";
$query .= "JOIN region ON region.id = info.region_id ";
$query .= "JOIN country ON country.region_id = region.id ";
$query .= "WHERE book_type.book LIKE '{$_POST['book_id']} AND nationality.natioalities LIKE '{$_POST['nationality_id']}' ";
$query .= "GROUP BY country.country ";
$query .= "ORDER BY country.country ASC ";
$check_country = mysqli_query($db_connection, $query);
// Generate HTML of country options list
if($check_country->num_rows > 0){
echo '<option value="">Please Select Your Country</option>';
while($row = $check_country->fetch_assoc()){
$country = ucwords(strtolower($row['country']));
echo '<option value="'.$country.'">'.$country.'</option>';
}
}
}
JQuery script :
$(document).ready(function(){
$('#nationality').on('change', function(){
var nationalityID = $(this).val();
if(nationalityID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'nationality_id='+nationalityID,
success:function(html){
$('#book').html(html);
$('#Country').html('<option value="">Please Select Nationality first</option>');
}
});
}else{
$('#book').html('<option value="">Please Select Nationality first</option>');
$('#country').html('<option value="">Please Select Book first</option>');
}
});
$('#book').on('change', function(){
var bookID = $(this).val();
if(bookID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'book_id='+bookID ,
success:function(html){
$('#country').html(html);
}
});
}else{
$('#country').html('<option value="">Please Select book first</option>');
}
});
});