salman233 Posted May 18, 2011 Share Posted May 18, 2011 hello everyone i am newbie to php just wanted to make a script for currency converter the problem i am facing is if i want to convert a value from $usd to $euro,$pond,$yen there are three possible values for usd kindly help me out with designing the values for tables and fetching data from them what will be structure of the table what will be the values kindly help me out it,s request thanks Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/ Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 Do you have a sample conversion rate? Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216807 Share on other sites More sharing options...
salman233 Posted May 18, 2011 Author Share Posted May 18, 2011 TAKE IT AS AN EXAMPLE LIKE 1EURO=2USD OR 2USD =1 EURO Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216809 Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 OK, so I found these sample rates here: http://www.x-rates.com/ You basically need either an array, or a table in mysql to store the conversion rates. I think an array would work nicely: $conversions = array( 'USD'=>1, 'GBP'=>1.62343, 'CAD'=>1.02554 ); Having that, you then would neet some way to convert the data. Probably a function: function br() { echo '<br/>'; } function converter($need, $have, $value, $conversionArray) { ($conversionArray[$have] / $conversionArray[$need]) * value; } var_dump($conversions); br(); echo converter('USD', 'GBP', 5.25, $conversions); br(); echo converter('GBP', 'CAD', 5.25, $conversions); Try it and let me know how it works. Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216812 Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 Sorry, did some error testing at the CLI, This works great: $conversions = array( 'USD'=>1, 'GBP'=>1.62343, 'CAD'=>1.02554 ); function br() { echo '<br/>'; } function converter($need, $have, $value, $conversionArray) { return (($conversionArray[$have] / $conversionArray[$need]) * $value); } var_dump($conversions); br(); echo converter('USD', 'GBP', 5.25, $conversions); br(); echo converter('GBP', 'USD', 5.25, $conversions); br(); echo converter('GBP', 'CAD', 5.25, $conversions); Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216818 Share on other sites More sharing options...
salman233 Posted May 18, 2011 Author Share Posted May 18, 2011 REALLY THANKS JOE I AM GOING TO TRY IT PLEASE ELABORATE MORE AS I AM A BEGINNER Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216820 Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 Where would you like me to start? Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216821 Share on other sites More sharing options...
salman233 Posted May 18, 2011 Author Share Posted May 18, 2011 FROM CREATING TABLE VALUES TO FETCHING THEM I REALLY APPRECIATE YOUR HELP BROTHER Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216824 Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 OK, In the example above we created an 'associative array'. This basically means that we are identifying the values of the array with 'keys' that contain string values. IE $conversions['USD'] = 1 in our case above. We created a function that accepts 4 arguments as parameters: function converter($need, $have, $value, $conversionArray) $need is the key value we want. $have is the key value we have. $value is the amount we have. $conversionArray is the array containing the Keys / values of our conversions. you can read more at http://www.php.net/manual/en/language.types.array.php, however I recommend you download the files locally for quicker reference: http://www.php.net/download-docs.php I have a .chm file on my desktop I love having it there! Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216826 Share on other sites More sharing options...
salman233 Posted May 18, 2011 Author Share Posted May 18, 2011 THanks joe workin on it catch u later if any help is required Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216842 Share on other sites More sharing options...
salman233 Posted May 18, 2011 Author Share Posted May 18, 2011 joe brother need help can you please tell me the whole code for this script including the database actually i want to get values from database i don,t know how to create table for this script Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216858 Share on other sites More sharing options...
jonsjava Posted May 18, 2011 Share Posted May 18, 2011 I hate to be the jerk, but you could do some of the coding. This is the "Help forum", not the "free labor" forum. If you give us bad code, we will help you fix it -- gladly. If you tell us to do all the work, you should be in the freelance section. edit Just noticed the freelance section is gone. Smeh. PM someone, and offer to pay them. Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216859 Share on other sites More sharing options...
salman233 Posted May 18, 2011 Author Share Posted May 18, 2011 THANKS JOE U HELPED ALOT MATE Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1216884 Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 Hey salman, I don't mind being of help. Jons does have a point though. Learning these topics will take a lot of time, trial & error, and studying. You can do it though! I would start off by installing xampp if you haven't already done so, you can create databases and tables fairly easy with phpmyadmin. Study the mysql functions in the php docs function->database extensions -> mysql reference. Try out some code, read, learn, try some more, when you run into a wall, come back and start a new thread. Good Luck! Link to comment https://forums.phpfreaks.com/topic/236710-want-help-with-currency-converter/#findComment-1217080 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.