lelliott92 Posted April 30, 2012 Share Posted April 30, 2012 How can I make my on change in the form pass through the year thats been selected, then use that in the second query? <select name="mySelect" onchange=""> <?php $result= mysql_query('SELECT DISTINCT Year FROM MonthlySales'); ?> <?php while($row= mysql_fetch_assoc($result)) { ?> <option value="<?php echo htmlspecialchars($row['Year']);?>"> <?php echo htmlspecialchars($row['Year']); ?> </option> <?php } ?> </select> <?php $query="SELECT * FROM MonthlySales WHERE Year = PASS YEAR SELECTED VARIABLE TO THIS BIT HERE"; $results = mysql_query ( $query, $conn); Quote Link to comment https://forums.phpfreaks.com/topic/261826-onchange-to-update-a-variable-and-pass-it-through-to-a-query/ Share on other sites More sharing options...
smerny Posted April 30, 2012 Share Posted April 30, 2012 the query is PHP (server side code ran when the page is loaded) onchange triggers javascript (client side code, ran when the menu changes.. well after the page is loaded) --- you cannot make the client side code do something on the server side without loading... but you can use ajax to load data sort of "behind the scenes" and make changes from that. Quote Link to comment https://forums.phpfreaks.com/topic/261826-onchange-to-update-a-variable-and-pass-it-through-to-a-query/#findComment-1341613 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.