Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

Interactive MySQL Query on a webpage

Hello Experts,
I have a web page where I want to let the user select a Currency from a dropdown menu.  
Using this value connect to a MySQL Table that lists the currency and exchange rate and using the currency as the selector return the exchange rate so I can calculate a price in the Selected Currency.
I can do a My SQL Query that will do this and can start it with PHP-That is query the table with the Currency and returning the exchange rate.
What I can't seem to figure out is how I could make this query with Javascript I do not have to write anything into this Table just retrieve the exchange rate.
I do not have ASP.NET or AJAX just a very simple site.
Thanks in advance.
Pseudo-Very Pseudo:
1.  From Drop Drown:
 
<select name="KDNWALO1" id="KDNWALO1" onChange="ShowCurr1();ShowCurr1a();"  style="width:180px; text-align:left; color: #0000FF; font-weight: bold; font-size: 10px;"/>    
                								<option selected="selected">Please Select Currency:</option>
                                                <option value="AUD">Australian Dollars</option>
                                                <option value="GBP">British Pounds</option>
                                                <option value="BGN">Bulgarian Leva</option>
                                                <option value="CAD">Canadian Dollars</option>
                                                <option value="CNY">Chinese Yuan Renminbi</option>
                                                <option value="HRK">Croatian Kuna</option>
                                                <option value="CYP">Cyprian Pounds</option>
                                                <option value="CZK">Czech Koruny</option>
                                                <option value="DKK">Danish Kroner</option>
                                                <option value="EEK">Estonian Krooni</option>
                                                <option value="EUR">Euros</option>
                                                <option value="HKD">Hong Kong Dollars</option>
                                                <option value="HUF">Hungarian Forint</option>
                                                <option value="ISK">Icelandic Kronur</option>
                                                <option value="IDR">Indonesian Rupiahs</option>
                                                <option value="JPY">Japanese Yen</option>
                                                <option value="LVL">Latvian Lati</option>
                                                <option value="LTL">Lithuanian Litai</option>
                                                <option value="MYR">Malaysian Ringgits</option>
                                                <option value="MTL">Malta Liri</option>
                                                <option value="NZD">New Zealand Dollars</option>
                                                <option value="NOK">Norwegian Krone</option>
                                                <option value="PHP">Philippine Pesos</option>
                                                <option value="PLN">Polish Zlotych</option>
                                                <option value="RON">Romanian New Lei</option>
                                                <option value="RUB">Russian Rubles</option>
                                                <option value="SGD">Singapore Dollars</option>
                                                <option value="SKK">Slovakian Koruny</option>
                                                <option value="SIT">Slovenian Tolars</option>
                                                <option value="ZAR">South African Rand</option>
                                                <option value="KRW">South Korean Won</option>
                                                <option value="SEK">Swedish Kronor</option>
                                                <option value="CHF">Swiss Francs</option>
                                                <option value="THB">Thai Baht</option>
                                                <option value="TRY">Turkish New Lira</option>
                                                <option value="USD">US Dollars</option>
                        </select>
2.  Query the MySQL File-Connects etc ommitted:
 
// Run the connection here 
// Run the connection here 
@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
@mysql_select_db("$db_name") or die ("no database");
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM engcur WHERE currency='$KDNWALO1'"); 
while($row = mysql_fetch_array($sql)){ 
$currency = $row[currency];
$rate = $row[rate];
}
 
3.  What is missing is a Javascript that will enable me to execute this query and retieve the $Rate variable

Open in new window

0
swedesamurai
Asked:
swedesamurai
1 Solution
 
nativestudiosCommented:
What your asking for will require AJAX (which is something handled by JavaScript).

The process is something like:

1. User selects 'Currency'
2. Javascript picks up the value of 'Currency' and then (using AJAX) passes it to your database lookup (PHP page)
3. The response is then passed back to javascript which then uses the exchange rate to calculate your price

Making the most out of AJAX will involve a good understanding of Javascript. I can recommend the 'Prototype.js' framework which simplifies many methods http://www.prototypejs.org/

Hope this helps

Andy
0
 
Michael701Commented:
well actually. because the rates are all known at the time the page is displayed they could all be included in the java script.

Just as you create the option list with php code you'd create the java if statements.
0
 
swedesamuraiAuthor Commented:
Took Michael701:advice and loaded the rates into hidden fields used a javascript tied into the value of the selection and used javascript to calculate rate changes based on currency change -works elegantly without ajax.  Thanks for the tip
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now