0

Without going into REAL specifics, lets just say I have a mysql table called Price with two data, Price A and Price B.

On my php page, I have Price A displayed by default. What I want to do now is give the visitor the option to display Price B instead of Price A. How can I achieve that? Can anyone help?

Many thanks

EDIT Okay more details: A price is listed on the website. This price is a data and is selected from my mysql table - lets call is HKD. In the same table there is another data called USD. I want to give the option to view the price in USD through a drop down menu. So if they person selects USD, it will retrieve from mysql table the USD data and display it, replacing the original HKD and vice versa when they select HKD again.

1
  • 1
    too vague, give us more details Commented Dec 12, 2012 at 9:17

5 Answers 5

1

Add a select list or a hyperlink for the users to change the results. Onchange the select or onclick the hyperlink will call an ajax function that updates the conents of the page

Sign up to request clarification or add additional context in comments.

Comments

0

You can select both values from DB and then decide in PHP witch one to display or you can use IF in SQL like this:

SELECT id, IF(:type = 'P', PriceA, PriceB) as Price FROM Prices 

Type is of course parameter.

Comments

0

You can try something like this:

Applicable  Rate:
<br>
Price A <span id='rate1'  onclick="applyrate(document.getElementById('AR'),document.getElementById('rate1').innerHTML)" style="cursor:pointer;background-color:red;"><?php echo "250"; ?></span> or Price B <span id='rate2' style="cursor:pointer;background-color:green;" onclick="applyrate(document.getElementById('AR'),document.getElementById('rate2').innerHTML)"><?php echo "300"; ?></span>

<input type='text' name='AR' id='AR' value='250'>

    <script>
        function applyrate(objR,valf)
        {
            objR.value=valf;
        }
    </script>

Comments

0

in the query change the column name from priceA to priceB.

Old

Select priceA as price from pricetable

Change to

Select priceB as price from pricetable

Comments

0

First in your sql statement select both of "price A" and "price B", then in your page use jquery like this:

<p id="price_a">$100.00</p>
<p id="price_b" style="display: none;">$95.00</p>
<input id="get_price" type="button" value="Alternative Price" />

$(document).ready(function() {
    $("#get_price").click(function() {
        $("#price_a").hide();
        $("#price_b").show();
    });
});​

With this way you don't have to reload the page or select data form your database again when the user choose to see the other price. Here is a Demo to see how it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.