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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Php price

  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Posts
    233
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Php price

    Hello i have problem with price of the room for hotel when should be 100 euros display 83 Euros.
    Example (One day staying cost € 100).For 14 days final price is € 1383 should be 1400 euros already tried number_format and money_format didn't work.Any help please.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Can you post the code that does the calculation.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Aug 2013
    Posts
    233
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Code

    $x2 = $_POST['endDate'];
    $x1 = $_POST['startDate'];

    $p1=strtotime("$x1");
    $p2=strtotime("$x2-1");
    $ps=strtotime("now");

    $vr1=($p1-$ps)/60/60/24;

    //echo $vr1;
    $vr2=$vr1+1;
    //echo "<br/>";
    //echo $vr2;
    //echo "<br/>";

    ($numberDays=($p2-$p1)/60/60/24);



    if( $vr2 < "0" )
    {
    echo "You didn't enter correct informations " .$_POST['startDate']. " push book now button. ";

    exit();

    }
    if ($p1>=$p2)
    {
    echo "Wrong booking " .$_POST['startDate']. " - " .$_POST['endDate']. " Try again to book. ";

    exit();

    }








    echo "You want reserve rooms in period by " .$_POST['startDate']. " until " .$_POST['endDate']. " in period by " .ceil($numberDays). " days ".ceil($numberDays)." (nights).";

    if($_POST['rooms']=="1")
    {
    $s1=100;


    echo "<br/>";
    //echo $s1. " -21";
    }
    else if ($_POST['rooms']=="2")
    {
    $s1=200;
    echo "<br/>";
    //echo $s1. " -22";
    }
    else if($_POST['rooms']=="3")
    {
    $s1=300;
    echo "<br/>";
    //echo $s1. " -23";
    }
    else if ($_POST['rooms']=="4")
    {
    $s1=400;
    echo "<br/>";
    //echo $s1. "
    }


    echo "<br/>";


    echo "<br/>";
    echo "<br/>";
    $price=$numberDays*$s1;
    // echo $price;








    print "You chose room number " .$_POST['rooms']. "(One day staying cost € " .$s1. ").For " .ceil($numberDays). " days final price is € " . ($price);

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Your calculation is getting fractions of days.

    $numberDays=($p2-$p1)/60/60/24;

    try the following instead

    $numberDays=floor($p2/60/60/24)-floor($p1/60/60/24)+1;
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Regular Coder
    Join Date
    Aug 2013
    Posts
    233
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Code

    Is not working coming out final price 0.

  • #6
    Regular Coder
    Join Date
    Aug 2013
    Posts
    233
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Any help

  • #7
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    You could try
    $numberDays= ceil(($p2-$p1)/60/60/24);

    but I'd need to do some testing to see if the issue is elsewhere.

    You really should be using better var names. Those names are horrible. Vars names should describe the data that they hold in a clear manner.

    And doing things like this is silly.
    Code:
    if($_POST['rooms']=="1")
    {
    $s1=100;
    
    
    echo "<br/>";
    //echo $s1. " -21";
    }
    else if ($_POST['rooms']=="2")
    {
    $s1=200;
    echo "<br/>";
    //echo $s1. " -22";
    }
    else if($_POST['rooms']=="3")
    {
    $s1=300;
    echo "<br/>";
    //echo $s1. " -23";
    }
    else if ($_POST['rooms']=="4")
    {
    $s1=400;
    echo "<br/>";
    //echo $s1. "
    }
    That would be better written as:
    Code:
    $s1 = 100 * $_POST['rooms'];
    Last edited by FishMonger; 09-06-2013 at 05:47 PM.

  • #8
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    Here's the short test script that I used.
    Code:
    <?php
    
    $start = '20 September 2013';
    $end   = '21 September 2013';
    
    $start_timestamp = strtotime($start);
    $end_timestamp   = strtotime("$end-1");
    
    #$numberDays=floor($end_timestamp/60/60/24)-floor($start_timestamp/60/60/24)+1; 
    $numberDays = ceil(($end_timestamp-$start_timestamp)/60/60/24);
    echo "$numberDays\n";
    
    ?>

  • #9
    Regular Coder
    Join Date
    Aug 2013
    Posts
    233
    Thanks
    16
    Thanked 0 Times in 0 Posts

    code

    Is not working any another solution.

  • #10
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,696
    Thanks
    25
    Thanked 657 Times in 656 Posts
    Look at this. It works for me. I have the POST[] defined at the top.
    PHP Code:
    <?php
    $_POST
    ['startDate'] = '2010-01-25';
    $_POST['endDate'] = '2010-01-26';
    $_POST["rooms"] = '1';

    $ending strtotime($_POST['endDate']);
    $starting strtotime($_POST['startDate']);

    $numberDays floor(abs($ending -$starting) / 86400);

    if (
    $starting>=$ending){
        echo 
    "Wrong booking " .$_POST['startDate']. " - " .$_POST['endDate']. " Try again to book. ";
        exit();
    }
    echo 
    "You want reserve ".$_POST["rooms"]." room(s) from " .$_POST['startDate']. " until " .$_POST['endDate']. " a period of " .ceil($numberDays). " day(s) and ".ceil($numberDays)." night(s).";
    if(
    $_POST['rooms']=="1"){
        
    $s1=100;
    }else if (
    $_POST['rooms']=="2"){
        
    $s1=200;
    }else if(
    $_POST['rooms']=="3"){
        
    $s1=300;
    }else if (
    $_POST['rooms']=="4"){
        
    $s1=400;
    }
    $price=$numberDays*$s1;
    echo 
    '<br />You must pay me $'.$price;
    ?>
    You can shorten the $s1 stuff, but I didn't.
    Last edited by sunfighter; 09-06-2013 at 07:44 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #11
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    Is not working
    That's a very poor problem statement.

    In what way did it fail?

    The test code I posted was not meant to pasted directly into your script and then work as expected. How did you take the code I showed and incorporate it into your script?

    The key part is the assignment of $numberDays. The assignment code I gave as well Sunfighter's will give the correct results. The assignment code that felgall added one more day than was needed/wanted.

  • #12
    Regular Coder
    Join Date
    Aug 2013
    Posts
    233
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Code

    My code was working well with $price but when i saw mistake that i have to take out endDate ($p2=strtotime("$x2-1")beacuse i wrote -1 that's for booking system and endDate not spouse to be count.

    I tried your code to replace mine i deleted mine and i paste yours i also tried to change couple things on your code to similar with mine or same
    did not work.


    <?php
    $_POST['startDate'] = '2010-01-25';
    $_POST['endDate'] = '2010-01-26';
    $_POST["rooms"] = '1';

    $ending = strtotime($_POST['endDate']);
    $starting = strtotime($_POST['startDate']);

    $numberDays = floor(abs($ending -$starting) / 86400);

    if ($starting>=$ending){
    echo "Wrong booking " .$_POST['startDate']. " - " .$_POST['endDate']. " Try again to book. ";
    exit();
    }
    echo "You want reserve ".$_POST["rooms"]." room(s) from " .$_POST['startDate']. " until " .$_POST['endDate']. " a period of " .ceil($numberDays). " day(s) and ".ceil($numberDays)." night(s).";
    if($_POST['rooms']=="1"){
    $s1=100;
    }else if ($_POST['rooms']=="2"){
    $s1=200;
    }else if($_POST['rooms']=="3"){
    $s1=300;
    }else if ($_POST['rooms']=="4"){
    $s1=400;
    }
    $price=$numberDays*$s1;
    echo '<br />You must pay me $'.$price;
    ?>
    You have my code what i did posted just try some solution in code for price and change that and post here that i can copy ad try in my code.

  • #13
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,696
    Thanks
    25
    Thanked 657 Times in 656 Posts
    If you used my code like you said in #12 post
    and it failed == Your doing something wrong!!!

    The top lines of this code
    PHP Code:
    $_POST['startDate'] = '2010-01-25';
    $_POST['endDate'] = '2010-01-26';
    $_POST["rooms"] = '1'
    simulates the calling page, if your using a page to call this code the top three lines must be commented out.
    Did you do that?

    did not work.
    What did not work????? What is being echoed to the screen?????
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #14
    Regular Coder
    Join Date
    Aug 2013
    Posts
    233
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Pearl_9

    I took out 3 lines of your code,and i always getting same echo one day of the reservation and price of the 100 euros.

  • #15
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,696
    Thanks
    25
    Thanked 657 Times in 656 Posts
    Ok. So really it worked. The problem has to be in the calling program. Paste that code here please.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    Pearl_9 (09-17-2013)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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