I have adapted some Javascript code for an application, I need to have two dropdown selections, the second dropdown options being dependent on what the user selects in the first. I then need to take that option, and on an onclick event, use the information to perform a calculation.
Using a tutorial I found I have managed to get the dependent dropdowns working by fetching the info from a mysql db using jquery and php. However, I only seem to be able to get the ‘name’ column for the dropdown, I need the ‘price’ as well to perform the calculation. I can get the ‘price’ column, but it just adds it to the array and lists it as additional options.
This is my code:
[code=php]$area = $_GET[“area”];
$query = “SELECT proxies.name, proxies.price FROM proxies INNER JOIN areas ON proxies.area_id=areas.id WHERE areas.name LIKE ‘{$area}'”;
$data = mysqli_query($conn, $query);
$proxies = [];
while($row = mysqli_fetch_array($data)){
array_push($proxies, $row[“name”],$row[“price”]);
}
echo json_encode($proxies);
Could anybody help me please, or point me in the right direction? Also, I’m not experienced with Javascript, and this solution feels a little ‘hack-y’ to me, is there a better way of doing it? Thank you.