Jump to content

displaying different queries depending on the select option


php_begins

Recommended Posts

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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.