Multiplying variables that contain numbers?

Discussion in 'PHP' started by mokimofiki, Aug 28, 2008.

  1. #1
    I am having trouble with multiplying variables that contain numbers any advice would be great.

    Current line that does the operation:
    $_SESSION['sppkgtotal'] = ($_SESSION['sppkgspecialqty']*$_SESSION['sppkgspecialprice'])+($_SESSION['sppkgwzoneqty']*$_SESSION['sppkgwindzoneprice']);

    It may just be that I have it written wrong .... Any thoughts would be great thank you.
     
    mokimofiki, Aug 28, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    what is the problem?
     
    mwasif, Aug 28, 2008 IP
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    $_SESSION['sppkgtotal'] shows no value its just blank when I echo or print it
     
    mokimofiki, Aug 28, 2008 IP
  4. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    This is how I grab the price could it be there?

    if(isset($_SESSION['sppkgspecial']))
    { $_SESSION['sppkgspecialprice'] = mysql_query("SELECT price FROM sppkg WHERE description=$_SESSION[sppkgspecial]"); }
     
    mokimofiki, Aug 28, 2008 IP
  5. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #5
    Try this
    if(isset($_SESSION['sppkgspecial'])) 
    {
              $row = mysql_fetch_array(mysql_query("SELECT price FROM sppkg WHERE description='".$_SESSION['sppkgspecial']."'"));
              $_SESSION['sppkgspecialprice'] = $row['price'];
    }
    Code (markup):
     
    mwasif, Aug 28, 2008 IP
    mokimofiki likes this.
  6. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #6
    $_SESSION['sppkgspecialqty']=(integer)$_SESSION['sppkgspecialqty'];
    $_SESSION['sppkgspecialprice']=(integer)$_SESSION['sppkgspecialprice'];
    $_SESSION['sppkgwzoneqty']=(integer)$_SESSION['sppkgwzoneqty'];
    $_SESSION['sppkgwindzoneprice']=(integer)$_SESSION['sppkgwindzoneprice'];
    $_SESSION['sppkgtotal'] = ($_SESSION['sppkgspecialqty']*$_SESSION['sppkgspecialprice'])+($_SESSION['sppkgwzoneqty']*$_SESSION['sppkgwindzoneprice']);
     
    octalsystems, Aug 28, 2008 IP
  7. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #7
    Great!! thank you ... now it rounds the values is that table of in the php?

    I don't want it to round if the price is 26.50 i want it to use 26.50 as the number to be multiplied? right now it used 27 even though the table says 26.50
     
    mokimofiki, Aug 28, 2008 IP
  8. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #8
    for each session variable do this before you multiply them:

    $_SESSION['sppkgtotal'] = (isset($_SESSION['sppkgtotal'] )) ? (float) $_SESSION['sppkgtotal'] : 0
     
    lanmonkey, Aug 28, 2008 IP