php_begins Posted July 12, 2011 Share Posted July 12, 2011 Hi. I do not know if I am in the right forum, but here is my problem. I have 2 query results stored in $query1 & $query2. I need to display the result of the different queries below the header section depending on the select option. For example, <h3><small>Show:</small> <select> <option><? echo Option 1 ?></option> <option><? echo Option 2?></option> </select> </h3> If the user chooses Option 1 it should display $query1 below the <h3> section. If the user chooses Option 1 it should display $query2 below the <h3> section. Any help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/241851-displaying-different-queries-depending-on-the-select-option/ Share on other sites More sharing options...
djlee Posted July 12, 2011 Share Posted July 12, 2011 theres a number of ways of doing this. Im guessing you do not want the page to refresh (if you did, you could just pass a get or post param on page load and show whichever query result was requested). So you will have to do it via javascript (basically, if you want to update page contents without refreshing the page, then this is the way to do it). The easiest way is to print out both query results into a wrapper (i use divs) then assign a id or class to each div, then when select changes, show the div that you need. I dont remember a lot of javascript since i started using jquery, so i cant provide exact code example, however heres a link to an example i made up that uses the jquery javascript library. If you dont use jquery, then you'll have to google for the relative "raw" javascript versions. http://jsfiddle.net/FMatc/1/ You can see the result in the bottom right box. The javascript code can be condensed and made to work more dynamically but ive made the javascript bulky so its easier for you to follow the flow and how it works Quote Link to comment https://forums.phpfreaks.com/topic/241851-displaying-different-queries-depending-on-the-select-option/#findComment-1242031 Share on other sites More sharing options...
php_begins Posted July 13, 2011 Author Share Posted July 13, 2011 Thanks for your reply.. I used jquery and did something similar to this page: http://www.danvega.org/blog/index.cfm/2008/7/1/jQuery-Select-Example Quote Link to comment https://forums.phpfreaks.com/topic/241851-displaying-different-queries-depending-on-the-select-option/#findComment-1242246 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.