www.webdeveloper.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 36

Thread: Need some help finishing my PHP program for class

  1. #16
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Additional corrections to be mentioned:

    Line 116: (missing bracket)
    Code:
    <!DOCTYPE html>
    Line 143+ (unquoted attributes)
    Code:
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    In regards to the summary information, you will need to collect more data in order to generate a report from. As you are already using the session to store the amount of entries, why not just store specific entry data as well.

    For example (Line 94):
    Code:
    $_SESSION['cnt'] = $_SESSION['cnt'] + 1;
    $_SESSION['fin'] = $_SESSION['fin'] + $fin;
    $_SESSION['entry' . $_SESSION['cnt']] = array(
    
    	'model'    => $model,
    	'features' => $features
    
    );
    After a few submission your session data would end up like this (using print_r($_SESSION);):
    Code:
    Array
    (
        [cnt] => 3
        [fin] => 2986.95
        [entry1] => Array
            (
                [model] => 30
                [features] => Array
                    (
                        [0] => 10.00
                        [1] => 3.00
                    )
    
            )
    
        [entry2] => Array
            (
                [model] => 30
                [features] => Array
                    (
                        [0] => 10.00
                        [1] => 3.00
                    )
    
            )
    
        [entry3] => Array
            (
                [model] => 30
                [features] => Array
                    (
                        [0] => 10.00
                        [1] => 3.00
                    )
    
            )
    
    )
    You could then loop through the data at a later stage and sum it up.
    Last edited by bionoid; 12-22-2013 at 01:37 PM.
    JavaScript: Learn | Validate | Compact | bionoid

  2. #17
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by bionoid View Post
    Additional corrections to be mentioned:

    Line 116: (missing bracket)
    Code:
    <!DOCTYPE html>
    Line 143+ (unquoted attributes)
    Code:
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    In regards to the summary information, you will need to collect more data in order to generate a report from. As you are already using the session to store the amount of entries, why not just store specific entry data as well.

    For example (Line 94):
    Code:
    $_SESSION['cnt'] = $_SESSION['cnt'] + 1;
    $_SESSION['fin'] = $_SESSION['fin'] + $fin;
    $_SESSION['entry' . $_SESSION['cnt']] = array(
    
    	'model'    => $model,
    	'features' => $features
    
    );
    After a few submission your session data would end up like this (using print_r($_SESSION);):
    Code:
    Array
    (
        [cnt] => 3
        [fin] => 2986.95
        [entry1] => Array
            (
                [model] => 30
                [features] => Array
                    (
                        [0] => 10.00
                        [1] => 3.00
                    )
    
            )
    
        [entry2] => Array
            (
                [model] => 30
                [features] => Array
                    (
                        [0] => 10.00
                        [1] => 3.00
                    )
    
            )
    
        [entry3] => Array
            (
                [model] => 30
                [features] => Array
                    (
                        [0] => 10.00
                        [1] => 3.00
                    )
    
            )
    
    )
    You could then loop through the data at a later stage and sum it up.

    Thanks for taking your valuable time out and helping me. I am new in PHP. You said "After a few submission your session data would end up like this (using print_r($_SESSION):" so all the have to go in the print statement?

  3. #18
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    print_r is a function that displays the contents of a variable. You can refer to it here: http://www.php.net/print_r

    The actual summary work will need to be done using a loop if you decide to use the recommendation above, for example:

    Code:
    for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {
    
    	echo 'Entry ' . $i . ' = ' . $_SESSION['entry' . $i]['model'] . ' / ' . count($_SESSION['entry' . $i]['features']) . '<br />';
    
    }
    Output Example (data dependant):
    Entry 1 = 30 / 2
    Entry 2 = 30 / 2
    Entry 3 = 30 / 2
    JavaScript: Learn | Validate | Compact | bionoid

  4. #19
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by bionoid View Post
    print_r is a function that displays the contents of a variable. You can refer to it here: http://www.php.net/print_r

    The actual summary work will need to be done using a loop if you decide to use the recommendation above, for example:

    Code:
    for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {
    
    	echo 'Entry ' . $i . ' = ' . $_SESSION['entry' . $i]['model'] . ' / ' . count($_SESSION['entry' . $i]['features']) . '<br />';
    
    }
    Output Example (data dependant):
    You been a great help! Thanks a lot.

  5. #20
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    715
    I was beat to the punch!

    Judging by the number of replies to your statement 'it runs perfect' I can see that you are not telling the truth.

    Merry Xmas - and I suggest dropping this course since you didn't learn anything.

  6. #21
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by ginerjm View Post
    I was beat to the punch!

    Judging by the number of replies to your statement 'it runs perfect' I can see that you are not telling the truth.

    Merry Xmas - and I suggest dropping this course since you didn't learn anything.
    If you don't trust me you can try to upload my script on the server and give it a shot. There is no reason for me to lie. Anyways thanks for your recommendation sir!

  7. #22
    Join Date
    Nov 2013
    Posts
    33
    A. The number of rentals entered
    you have done this.

    As for the next 3 I don't understand how you want this to work as sessions are only alive for the life of the browser window being open.
    B. Total Amount of all rentals entered

    C. Percentage of rentals which were high end models (luxury, minivan, suv)

    D. Percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.

    Once you close the browser is closed all session data will be lost.

    Also you seem to asking a math question, not so much a code problem.

    As a mathematical issue to get the percentage divide by 100

    Whilst it may seem that we are being unhelpful it should be understood that most of us want the people we help to learn and hopefully discover the solution themselves especially when their question is based on a assignment.

  8. #23
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by unasAquila View Post
    A. The number of rentals entered
    you have done this.

    As for the next 3 I don't understand how you want this to work as sessions are only alive for the life of the browser window being open.
    B. Total Amount of all rentals entered

    C. Percentage of rentals which were high end models (luxury, minivan, suv)

    D. Percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.

    Once you close the browser is closed all session data will be lost.

    Also you seem to asking a math question, not so much a code problem.

    As a mathematical issue to get the percentage divide by 100

    Whilst it may seem that we are being unhelpful it should be understood that most of us want the people we help to learn and hopefully discover the solution themselves especially when their question is based on a assignment.

    I do understand what you mean. The problem is if I knew how to do it, I wont be asking help. I know it's not much left probably few more lines. It's my mistake I took PHP class as a free elective. Earlier I was accused of lying without the person running my script. I am not here to argue with other users but others should check before they accuse someone. Anyhow I appreciate you helping me out.

  9. #24
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    I'm curious to know when this is due, I thought most places had already closed for the holidays?
    JavaScript: Learn | Validate | Compact | bionoid

  10. #25
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by bionoid View Post
    I'm curious to know when this is due, I thought most places had already closed for the holidays?
    This is due tomorrow before midnight.

  11. #26
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by bionoid View Post
    I'm curious to know when this is due, I thought most places had already closed for the holidays?
    It's a online class, I requested my instructor for late assignment submission.

  12. #27
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    OK, then how are you coming along? Do you have what you need to complete it now?
    JavaScript: Learn | Validate | Compact | bionoid

  13. #28
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by bionoid View Post
    OK, then how are you coming along? Do you have what you need to complete it now?
    I don't understand how to put the code in for summary percentage. To be honest I'm still completely lost. When I make changes the page turns blank (white)

  14. #29
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    ok, whatever you've done... post it here again. remember to place [ code ][ /code ] tags without the spaces around it. Then we can sort this out.
    I don't think you included the final page code here before anyway, would be nice to see.
    JavaScript: Learn | Validate | Compact | bionoid

  15. #30
    Join Date
    Dec 2013
    Posts
    21
    <?php
    session_start();
    if (!(isset($_POST['first_time']))) {
    $_SESSION['cnt'] = 0;
    $_SESSION['fin'] = 0;


    }

    if (isset($_POST['submit'])) {
    // Address error handling

    // Get the values from the $_POST array:
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $deposit=$_POST['deposit'];
    $days=$_POST['days'];
    $beginningmileage=$_POST['beginningmileage'];
    $endmileage=$_POST['endmileage'];
    $ins=$_POST['coverage'];
    $discount=$_POST['discount'];
    $drivers=$_POST['drivers'];
    $model=$_POST['model'];
    $under25=$_POST['age'];
    $gastank=$_POST['gas'];
    $gallons=$_POST['gallons'];
    $features=$_POST['features'];

    // Validate the firstname
    if(empty($_POST['firstname'])) {
    print '<p> Please enter your first name.</p>';
    $okay= FALSE;
    }
    // Validate the lastname
    if(empty($_POST['lastname'])) {
    print '<p> Please enter your last name.</p>';
    $okay= FALSE;
    }
    // Validate the days
    if (is_numeric($_POST['days'])) {

    //Check that days is greater then 0.
    if ($_POST['days']< 1) {
    print '<p> You must enter days greater then 0</p>';
    $okay= FALSE;
    }
    }
    else {
    print '<p> Number of days are not numeric</p>';
    $okay= FALSE;
    }

    //Calculate the total:
    $daily= $model* $days;
    $mileage= ($endmileage-$beginningmileage-($days*100))*.35;
    if ($mileage<0)
    $mileage=0;
    $drivers=($drivers-1)*5*$days;
    $sub= $daily+$mileage+$drivers+features;
    $coverage=$sub*.1*$ins;
    $tax= $sub *0.05;
    $tot=0;
    foreach ($features as $charge){
    $tot=$tot+$charge;
    }
    $extra=$tot*$days;



    $fin=$sub+$coverage+$tax+$extra-$deposit;
    $fin=$fin-($fin*$discount);
    $daily=number_format($daily,2);
    print "daily:$$daily<br/>";
    $mileage=number_format($mileage,2);
    print "mileage:$$mileage<br/>";
    /*print "mileage chargeprin:<br/>
    */
    $drivers=number_format($drivers,2);
    print "drivers:$$drivers<br/>";
    $underdrivers=$under25*$days;
    if ($gastank=="E"){
    $gascharge=$gallons*3;}
    else{$gascharge=$gallons*3;}
    $sub=number_format($sub,2);
    print "extra:$$extra<br/>";
    print "discount:$discount<br/>";
    print "sub:$$sub<br/>";
    $coverage=number_format($coverage,2);
    print "coverage:$$coverage<br/>";
    $fin=number_format($fin,2);
    print "fin:$$fin<br/>";

    print $_SESSION['cnt'] = $_SESSION['cnt'] + 1;
    print $_SESSION['fin'] = $_SESSION['fin'] + $fin;



    print '<form method="post" action="Test2.php">
    <p><input name="rentals" value="Enter New Rental" type="submit"></p>
    <p><input name="finish" value="Complete All Rentals" type="submit"></p>
    <input type="hidden" name="first_time" value="true">
    </form>';
    }
    else
    {
    if (isset($_POST['finish'])) {
    print "Summary Form"
    print "Here is the count " . $_SESSION['cnt']<br/>;
    print "Total amount of all rentals" . $_SESSION['fin'];<br/>




    }

    else {

    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles