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 Quote Link to comment Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 Do you have a sample conversion rate? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
phpJoeMo Posted May 18, 2011 Share Posted May 18, 2011 Where would you like me to start? Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
salman233 Posted May 18, 2011 Author Share Posted May 18, 2011 THANKS JOE U HELPED ALOT MATE Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.