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 16

Thread: Booking system

  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Booking system

    I have little problem i am not getting all number like result.

    You want reserve rooms in period by 30-09-2013 until 01-12-2013 in period by 62.041666666667 days ( 62.041666666667 nights).



    You chose room number 1(One day staying cost 100).For 62.041666666667 days final price is 6204.1666666667



    You want[ 1 ]rooms . You have [ 1 ]kids. You have[ 1 ]adult.
    More often i am getting right result but sometimes if result is above 60 i am getting like 62.0416666667.





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

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

    $vr1=($p1-$ps)/86400; //

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

    $numberdays=($p2-$p1)/86400;



    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. ";
    $insertGoTo = "/001shsz/index.html";
    exit();

    }








    echo "You want reserve rooms in period by " .$_POST['startDate']. " until " .$_POST['endDate']. " in period by " .$brojDana. " days ( ".$brojDana." 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. " -24";
    }


    echo "<br/>";


    echo "<br/>";
    echo "<br/>";
    $price=$numberdays*$s1;
    // echo $price;
    echo "You chose room number " .$_POST['rooms']. "(One day staying cost " .$s1. ").For " .$numberdays. " days final price is " .$price;

  • #2
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Pearl_9 View Post
    (Only for experts)

    I have little problem i am not getting all number like result.

    You want reserve rooms in period by 30-09-2013 until 01-12-2013 in period by 62.041666666667 days ( 62.041666666667 nights).



    You chose room number 1(One day staying cost 100).For 62.041666666667 days final price is 6204.1666666667



    You want[ 1 ]rooms . You have [ 1 ]kids. You have[ 1 ]adult.
    More often i am getting right result but sometimes if result is above 60 i am getting like 62.0416666667.





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

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

    $vr1=($p1-$ps)/86400; //

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

    $numberdays=($p2-$p1)/86400;



    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. ";
    $insertGoTo = "/001shsz/index.html";
    exit();

    }








    echo "You want reserve rooms in period by " .$_POST['startDate']. " until " .$_POST['endDate']. " in period by " .$brojDana. " days ( ".$brojDana." 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. " -24";
    }


    echo "<br/>";


    echo "<br/>";
    echo "<br/>";
    $price=$numberdays*$s1;
    // echo $price;
    echo "You chose room number " .$_POST['rooms']. "(One day staying cost " .$s1. ").For " .$numberdays. " days final price is " .$price;
    Any suggestions what i am suppose to do.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Use a print formatter or number_format/money_format. Money_format would be the best if its available since it can be given a locale instead and it will render the currency for you (pounds, euro's, whatever).
    The problem is a simple round calculation. Money_format will only work in 2 relevant digits, number_format is given the number of significant digits, and [s]printf works with floating point precision. Money_format is the best for monies since it adds the currency symbols by default, but it does require strfmon capabilities (so. . . not a windows machine).
    Float numbers you'll definitely need to round for the significant digits; the nights needs to be ceil() called. All other methods will round, so you could end up with 60.4 becoming 60 when it should be 61 presumably.
    Some examples:
    PHP Code:
    $number 1234.5678;

    setlocale(LC_MONETARY'en_GB');
    printf("Amount: %s" PHP_EOLmoney_format("%n"$number));

    printf("Amount: %0.2f" PHP_EOL$number);
    printf("Amount: %s" PHP_EOLnumber_format($number2)); 
    Code:
    Amount: 1,234.57
    Amount: 1234.57
    Amount: 1,234.57
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Booking system

    First i want thank you for trying to help me,i really appreciate.I hope so that we will fix this.

    I am not sure what do but i did insert this code which you wrote in my code ad didn't work,then i tried replace echo with print didn't work either.Can you please write in code which i posted what i have to add or delete or replace.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    None of my code will help you. These are examples, you need to change your code to match the same methods with preference on using locale aware functions such as money_format. Find where you need to change the monetary displays and use money_format, and where you need to find integer values rounded up use the ceil() function. You can change the variables themselves, but I would suggest you either make a new variable with the output formats changed or you do it directly within the output. This lets you make further use of the variables if you need to do more calculations later with them. Sometimes rounded does make sense; the number of days variables can be rounded to an even integer number when calculated since it's highly improbable that there are any fractional days provided. These are all based on whatever the business rules are for the application.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Booking system

    Right here is problem from here everything starts



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



    If i want reserve more then 60 days i am getting this
    You want reserve rooms in period by 29-09-2013 until 31-12-2013 in period by 93.041666666667 days ( 93.041666666667 nights).
    and of course i getting price something like 9304.1666666667.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Right, so use ceil() to round up the $numberdays variables. That would make it 94 days assuming you want that.
    Pricies use the money_format or number_format if you have no strfmon capable server.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts
    if i use ceil() to round up the $numberdays variables i am getting error tried to avoid error on different ways but couldn't.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I can't really tell you what is broken unless you post the error and the code associated with it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #10
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts

    code

    This is code try to add ceil() by $numberdays you will get error

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

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

    $vr1=($p1-$ps)/86400; //

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

    $numberdays=($p2-$p1)/86400;



    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. ";
    $insertGoTo = "/001shsz/index.html";
    exit();

    }








    echo "You want reserve rooms in period by " .$_POST['startDate']. " until " .$_POST['endDate']. " in period by " .$brojDana. " days ( ".$brojDana." 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. " -24";
    }


    echo "<br/>";


    echo "<br/>";
    echo "<br/>";
    $price=$numberdays*$s1;
    // echo $price;
    echo "You chose room number " .$_POST['rooms']. "(One day staying cost " .$s1. ").For " .$numberdays. " days final price is " .$price;


    Try that code i Dreamweaver or what ever you use make two inputs for startDate and endDate then try to fix it.







    But i think is right here is problem try to add ceil() here to


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

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Works fine for me. I mean you have tons of other issues in this code and its pretty twisted up, but there is no issue with the ceil() call.
    Perhaps you should start by reading this documentation: http://php.ca/manual/en/language.functions.php. It should give you an idea of how to properly call functions.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #12
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Smile code

    I have fixed difference between days but the price is messed up if it is going over 60 days.
    Example
    You want reserve rooms in period by 29-09-2013 until 29-12-2013 in period by 92 days 92 nights.



    You chose room number 1(One day staying cost 100).For 92 days final price is 9105

    Should be 9200.

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Standard calculation problems. Go waaaay back to where I said you have to decide if you are rounding during output or during calculations. These are things that are based on business rules.
    Not sure exactly what step you ended up with 92 though, there are only 91 days between them (1 + 31 + 30 + 29 = 91). As timestamps when you divide them though, you do end up with a fractional value (which is normal during calculations). So your problem is precision loss since the same will not necessarily apply to all values, so you cannot reliably choose round, floor or ceil as your options without reversing it to verify.

    Make use of the DateTime objects and DateInterval instead. This will give you an object that has the number of days that have passed and is more reliable and locale aware. It will require PHP 5.3+ to operate.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #14
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Code

    From and including: Sunday, September 29, 2013
    To and including: Sunday, December 29, 2013

    Result: 92 days
    It is 92 days from the start date to the end date, end date included

    Or 3 months, 1 day including the end date
    //www.timeanddate.com/date/durationresult.html?m1=9&d1=29&y1=2013&m2=12&d2=29&y2=2013&ti=on
    (checl link for diffrence between days)
    I have php 5.3

  • #15
    Regular Coder
    Join Date
    Aug 2013
    Posts
    130
    Thanks
    5
    Thanked 0 Times in 0 Posts
    How can i endDate avoid when doing calculation to get right result.


  •  
    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
    •