SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Webservice working but some questions

    1. This webservice is working converting the values from the select inputs "FromCurrency" and "ToCurrency" on the action page. The value is calculated fine and output as
    PHP Code:
    echo $fConversionRate
    What I am trying to do is to multiply the $fConversionRate value on the action page by the form field valuetoconvert which I believe will appear as the following on the action page:
    PHP Code:
    $_GET['ValuetoConvert'
    I have tried various combinations along the lines of ( conversionrate * valuetoconvert) but it doesn't seem to work. How can I output this value please do that please?

    2. I could harcode the values into the FromCurrency and ToCurrency select drop downs but would rather output them from the webservice. How can I do that? Thank-you.

    Attached is the zip with the lib folder needed to make the nusoap webservice work if you want to see how it works on you local machine,. Thanks again

    PHP Code:
    <?php
    require_once 'lib/nusoap.php';

    $oClient   = new nusoap_client(

        
    'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL',

        
    TRUE // Needs to be TRUE because we are using WSDL

    );

    ?>

    <form action="ws.php" method="get">
    <p>
    Convert from:
    <select name="FromCurrency">
    <option value="USD">UnitedStatesDollar</option>
    </select>
    </p>

    <p>
    convert to:
    <select name="ToCurrency">
    <option value="CAD">CanadianDollar</option>
    </select>
    </p>

    Value to convert:<input type="text" name="ValueToConvert" /><br />

    <input type="submit" />

     </form>
    Action page ws.php
    PHP Code:
    <?php

    require_once 'lib/nusoap.php';

    $oClient   = new nusoap_client(
        
    'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL',
        
    TRUE // Needs to be TRUE because we are using WSDL
    );
    $oResponse $oClient->call(
        
    'ConversionRate',
        array( 
            
    'FromCurrency' => $_GET['FromCurrency'],
            
    'ToCurrency'   => $_GET['ToCurrency']
        )
    );

    $fConversionRate = (float) $oResponse['ConversionRateResult'];
    echo 
    $fConversionRate
    ?>

    <!--output all vars to see what is going on
    <?php
    $vars 
    get_defined_vars();
    print_r($vars);
    ?>-->
    Attached Files Attached Files

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    This is very basic PHP, please take the time to look over the Manual on basic arithmetic: http://php.net/operators.arithmetic

    You will be wanting to do something along the lines of:
    PHP Code:
    $fConvertedValue = (float) $_GET['ValuetoConvert'] * $fConversionRate
    I'll leave it as an exercise for the reader to decide where that goes and how to use it.
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •