CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2009
    Posts
    144

    How to multiplication....

    hello everybody, i have a problem and i think someone of you could solve it.

    i have this line of code

    Code:
    $price2 =$row['price'] * $quantity;
    echo $price2;
    echo gives me : 200(price)3(quantity) like 2003 and not 600 as i want...

    $row['price'] is from my database (varchar column, tried with int column)
    and quantity is

    $_SESSION["products"] as $product => $quantity

    i tried these:

    Code:
    (int)$price2 =$row['price'] * $quantity;
    echo $price2;
    
    $price2 =(int)$row['price'] * (int)$quantity;
    echo $price2;
    
    
    (int)$price2 =(int)$row['price'] * (int)$quantity;
    echo (int)$price2;
    none worked for me... can anyone help me?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: How to multiplication....

    PHP will automatically converts object type. You don't need to do that yourself. In fact, the only way it should be concatenating is if you are using a "." instead of a "*".

    I guess you could try the following...
    Code:
    $price2 = ($row['price']) * ($quantity);
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 2009
    Posts
    144

    Re: How to multiplication....

    Code:
    $price2 =($row['price']) * ($quantity);
    echo $price2;
    and i get 700200 for example... i want 140000

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: How to multiplication....

    Strange. PHP should always do variable type conversion. Try using intval().
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Nov 2009
    Posts
    6

    Re: How to multiplication....

    Do your variables echo to what you expect?

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured