SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: How to multiply

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

    How to multiply

    How do I multiply this variable which I am successfully outputting $fconversionRate

    with this form field

    $_GET['ValuetoConvert']

    You can see how I am outputting $fconversionRate at the moment at the end of the code below. Thank you very much:

    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; ?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Why dont you post the exact results of doing this :

    var_dump( $fConversionRate );

    and the exact results of this:

    var_dump( $_GET['ValuetoConvert'];

    Then someone may be able to help you.

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ill do that
    Last edited by Bayliss Trevor; May 2, 2009 at 21:22.

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The exact results of this:

    var_dump( $fConversionRate );


    are NULL

    var_dump( $_GET['ValuetoConvert']);


    are NULL

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    something like:
    PHP Code:

    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']; 
    $result $fConversionRate * isset($_GET['ValuetoConvert']) ? $_GET['ValuetoConvert'] : 0;
    echo 
    $fConversionRate;
    echo 
    $result
    should work.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Spike it outputs the conversion rate on the action page but it doesn't do the multiplication. The results of the following var_dumping:
    PHP Code:
    var_dump$fConversionRate );
    var_dump$_GET['ValuetoConvert']); 
    is:

    float(1.1857) NULL

    It seems as if maybe the value isn't being passed from the form.php ValueToConvert field? Why is this not working? Thank-you

    Form.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

    );

    ?>


    <form action="action.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.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']; $result 

    $fConversionRate * isset($_GET['ValuetoConvert']) ? $_GET['ValuetoConvert'] : 0;echo 

    $fConversionRate;echo $result;  

    ?>

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    hmm add the following to your var_dump area

    PHP Code:
    print_r($_GET); 
    and see what is being sent through, paste the results.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    float(1.1857) NULL Array ( [FromCurrency] => USD
    [ToCurrency] => CAD
    [ValueToConvert] => 30 )

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    ah-ha, this is one of those really REALLY annoying errors!

    ValueToConvert is different to ValuetoConvert - note the capital T!

    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']; 
    $result $fConversionRate * isset($_GET['ValueToConvert']) ? $_GET['ValueToConvert'] : 0;
    echo 
    $fConversionRate;
    echo 
    $result;  

    ?>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Now, how do you know that 30 represents 30 cents or 30 dollars?

    Signal clearly on your gui.

  11. #11
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right php it is strongly typed! I didn't realize that. Thanks cups I now added that in on the form.
    The sum doesn't seem to happen though if I convert 30 from USD to CAD then I get 1.185710 on the action page-it should be 1.185710 *30 I think.
    Why is that happenig? Thanks

    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']; $result 

    $fConversionRate * isset($_GET['ValueToConvert']) ? $_GET['ValueToConvert'] : 0;
    echo 
    $fConversionRate;
    echo 
    $result;  


    ?>

  12. #12
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why is this part

    PHP Code:
    $fConversionRate = (float) $oResponse['ConversionRateResult']; 
    $result =  $fConversionRate * isset($_GET['ValueToConvert']) ? $_GET['ValueToConvert'] : 0
    echo 
    $fConversionRate; echo $result
    not
    PHP Code:
    $fConversionRate = (float) $oResponse['ConversionRateResult']; 
    $result =  $fConversionRate *  $_GET['ValueToConvert'] ;
    echo 
    $result
    Thanks

  13. #13
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works! thanks for all the help with my first php coding!

  14. #14
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Why is this part
    He was showing you how to use the Ternary Operator in PHP - making sure the $_GET value was set.

    if( this is true ) ? do this : do that ;

    equivalent to:

    if( this is true ) {
    do this ;
    } else {
    do that ;
    }

  15. #15
    SitePoint Evangelist
    Join Date
    Mar 2008
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah ok Cups, I thought it was something like that. However, it didn't work.


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
  •