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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.