I've been looking at a dozen or more php mysql jquery ajax tutorial sites/plugins but all of them seem to be hard coding the values or value sets into ajax/jquery/json rather than just link the drop downs as I require. I also checked stackoverflow whether there was anything, but the examples were all hardcoded.
Desired workflow
1. Select value in drop down 1 2. define a variable in drop down 2 or in mysql select that takes value from drop down 1 and limit the options or change the options as required
Relevant Database Structure
Table : price_change ID | price_word | amount | max_ 3 | 10 Lacs | 1000000 | 0 4 | 25 Lacs | 2500000 | 0 1 | >10 Lacs | 999999 | 0 2 | 1 Crore | 10000000 | 1 11 | 10 Crores | 100000000 | 1 10 | 5 Crores | 50000000 | 1 7 | 1.25 Crores | 12500000 | 2 8 | 1.5 Crores | 15000000 | 2 9 | 2 Crores | 20000000 | 2 5 | 50 Lacs | 5000000 | 2 6 | 75 Lacs | 7500000 | 2
I have a prepared statement that selects the data and displays results as per the query
function db_select($query) {
$rows = array();
$result = db_query($query);
// If query failed, return `false`
if($result === false) {
return false;
}
// If query was successful, retrieve all the rows into an array
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
Current code for generating values for drop down 1
<select name="minprice" id="minprice" >
<?php
$rows = db_select("SELECT amount,price_word FROM price_change where max_<>'1' ");
foreach($rows as $row){
echo "<option value='".$row['amount']."'>".$row['price_word']."</option>";
}
?>
</select>
Current code for generating values for drop down 2
<select name="maxprice" id="maxprice">
<?php
$rows = db_select("SELECT amount,price_word FROM price_change where max_<>'0' ");
foreach($rows as $row){
echo "<option value='".$row['amount']."'>".$row['price_word']."</option>";
}
?>
</select>
In order for drop down 2 to always be more than drop down 1, I need to define a variable that can be used to ensure this.
so ideally it would be like this SELECT amount,price_word FROM price_change where max_<>'0' AND amount>=$dropdown1
I know this will involve some ajax/jquery but I want to ensure that the code is reusable so I don't hard code the values or select elements.
Can someone please point me in the right direction as I have been trying to do this for hours
I hope there is enough information to assist me in a solution, but if I missed something and if there is a better way to do this, please let me know.
EDIT - This works - http://www.plus2net.com/php_tutorial/dd.php but the only problem is that it runs a simulation of page refresh with new url which I don't want. I basically want the URL to be the same. But this is a step in the right direction as it doesn't hard code the values or selects or anything