Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to get 5% out of any given number

    Does anyone know the formula in php to get 5% from any given number?
    For example: like on my site it shows that lets say I made $300.00 today and I get to keep 5% of that so now I want it to show 5% of 300 which is 60. so I would get to keep $60.00 dollars.

    How or what is the code to get 5% of any number in php?

    If there are any questions please let me know! Thanks guys!

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Sounds like basic math to me...

    PHP Code:
    $rate 5.00//percent
    $totalAmount 300.00

    $commission 
    $totalAmount*($rate/100);
    print 
    $commission

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok thanks man I freaking had a brain freeze! I went to bed way to late! lol thankx so much!

  • #4
    New Coder
    Join Date
    Jul 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so now here is my big question. I have tried a lot of things and I cant multiply 0.05 by sales (a number in the database). How would I do that with $row['sales']; in the code?

    Here is part of the code:

    PHP Code:
    <?php

    $con 
    mysql_connect("localhost""root""blah");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      
      }
    mysql_select_db("Bus"$con);
      
    $query "SELECT drivers.last_name, sales.meals, sales.date, sales.bus, sales.sales,
    sales.percent "
    .
     
    "FROM drivers, sales ".
        
    "WHERE drivers.PID = sales.drivers_DID"
         
        
    $result mysql_query($query) or die(mysql_error());


    // Print out the contents of each row into a table 
    while($row mysql_fetch_array($result)){
        
      echo 
    $row['sales'];

    }

    ?>


  •  

    Posting Permissions

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