Professional Web Applications Themes

arrays - PHP Development

hi I have a project to finish in php. I have to send some values and make calculation through email. Actually I found the solution for sending hidden values through email. But the solution is just a few items . If there are alot of items i a ed. Because i have to write a long listing code. This doesnt make sense. Here is my code so you can understand what i mean. a piece of my html code is <form method="POST" action="estimate.php"> <input type="text" size="2" maxlength="3" name="item_2" class="txt2"><input type="hidden" name="Weight_2" value="65"><input type="hidden" name="Name_2" value="Bookshelves, per section"></td> <td class="txt3">&nbsp;Chair, Arm</td> ...

  1. #1

    Default arrays

    hi
    I have a project to finish in php. I have to send some values and make
    calculation through email. Actually I found the solution for sending hidden
    values through email. But the solution is just a few items . If there are
    alot of items i a ed. Because i have to write a long listing code. This
    doesnt make sense. Here is my code so you can understand what i mean.


    a piece of my html code is
    <form method="POST" action="estimate.php">
    <input type="text" size="2" maxlength="3" name="item_2" class="txt2"><input
    type="hidden" name="Weight_2" value="65"><input type="hidden" name="Name_2"
    value="Bookshelves, per section"></td>
    <td class="txt3">&nbsp;Chair, Arm</td>
    <td class="txt3">
    <input type="text" size="2" maxlength="3" name="item_3"
    class="txt2"><input type="hidden" name="Weight_3" value="60"><input
    type="hidden" name="Name_3" value="Chair, Arm"></td>
    </tr>
    <tr>
    <td class="txt3">Chair Rocker (wood)</td>
    <td class="txt3">
    <input type="text" size="2" maxlength="3" name="item_4"
    class="txt2"><input type="hidden" name="Weight_4" value="40"><input
    type="hidden" name="Name_4" value="Chair Rocker (wood)"></td>
    <td class="txt3">&nbsp;Chair Overstuffed</td>
    <td class="txt3">
    <input type="text" size="2" maxlength="3" name="item_5"
    class="txt2"><input type="hidden" name="Weight_5" value="120"><input
    type="hidden" name="Name_5" value="Chair Overstuffed"></td>
    </tr>
    <tr>
    <td class="txt3">Chair Straight</td>
    <td class="txt3">
    <input type="text" size="2" maxlength="3" name="item_6"
    class="txt2"><input type="hidden" name="Weight_6" value="25"><input
    type="hidden" name="Name_6" value="Chair Straight"></td>
    <td class="txt3">&nbsp;Desk, Small</td>
    <td class="txt3">
    <input type="button" value="SUBMIT ESTIMATION REQUEST" name="submit">

    my php code is ;

    <?php
    $FTGName_2 = $item_2 * $Weight_2;
    $FTGName_3 = $item_3 * $Weight_3;
    $FTGName_4 = $item_4 * $Weight_4;
    $FTGName_5 = $item_5 * $Weight_5;
    $FTGName_6 = $item_6 * $Weight_6;

    $FTGtotal = $FTGName_2 + $FTGName_3 + $FTGName_4 + $FTGName_5 + $FTGName_6;

    $body = "$Name_2 : $FTGName_2\n"
    . "$Name_3 : $FTGName_3\n"
    . "$Name_4 : $FTGName_4\n"
    . "$Name_5 : $FTGName_5\n"
    . "$Name_6 : $FTGName_6\n"


    ?>

    if there is not alot of item it is fine. But what if i have hundred item.
    How am i going to calculate. I use some for loop but i didnt work very well.
    Can somebody help me please. I m going crazy over here.

    Thanks in advance




    ozgur Guest

  2. #2

    Default Re: arrays


    Please do not cross post (send a single message to multiple groups). If
    you want to send it to more than one group just send one message with
    all the groups listed in the header and set follow-ups to a single
    group. See http://home.icomnet.com/support/usenet.shtml

    I answered you in alt.php.


    -veikko

    --
    veikko
    mail .com
    makinen
    Veikko Guest

  3. #3

    Default Re: arrays

    "ozgur teksin" <com> wrote in message
    news:com... 

    The above can be also:
    $FTGName[2] = $_REQUEST["item_2"] * $_REQUEST["Weight_2"];

    And that can be then turned into a loop
    for($z=2;$z<6;$z++)
    $FTGName[$z] = $_REQUEST["item_$z"] * $_REQUEST["Weight_$z"];
     

    This can be done inside the previous loop:
    for($z=2;$z<6;$z++){
    $FTGName[$z] = $_REQUEST["item_$z"] * $_REQUEST["Weight_$z"];
    $FTGtotal += $FTGName[$z];
    }
     

    This can also be done inside the previous loop:
    for($z=2;$z<6;$z++){
    $FTGName[$z] = $_REQUEST["item_$z"] * $_REQUEST["Weight_$z"];
    $FTGtotal += $FTGName[$z];
    $body .= $_REQUEST["name_$z"] . " : " . $FTGName[$z] . "\n";
    }

    So basiclly that's all you need. And by modifying the starting value of $z
    (now 2) and the ending value (now 6) you should be able to loop throught
    like 100 items, or a thousand. For example for($z=0;$z<100;$z++){...
     

    No need to go crazy.
     

    no problemo.

    --
    Welcome to Usenet! Please leave tolerance, understanding
    and intelligence at the door. They aren't welcome here.
    eternal piste erection miuku gmail piste com


    Kimmo Guest

  4. #4

    Default arrays and variables

    Hi guys,

    Thanks for your help.

    Can anyone tell me what is wrong with this script. Because I couldt send the
    values of Name_2 or Name_3 when I submit the form and check the email.
    This is just a piece of my html and my php code. Name_2 ....... Name_200.
    Thanks again in advance


    for example

    Name : whatever
    Res Phone : 9458943
    Email : whateverwhatever
    Bus Phone : 9489584
    The Total is 230

    I would like to get by submission

    Name : whatever
    Res Phone : 9458943
    Email : whateverwhatever
    Bus Phone : 9489584
    Bookshelves : 130
    Chair : 60
    Chair Rocker : 40
    The Total is 230

    Here is my html

    <form method="POST" name="EstimationForm" action="estimate.php">
    <input type="text" name="GI_name" size="24" class="txt2">
    <input type="text" name="GI_resphone" size="24" class="txt2">
    <input type="text" name="GI_email" size="24" class="txt2">
    <input type="text" name="GI_busphone" size="24" class="txt2">

    <input type="text" size="2" maxlength="3" name="item_2" class="txt2"><input
    type="hidden" name="Weight_2" value="65">
    <input type="hidden" name="Name_2" value="Bookshelves, per section"></td><td
    class="txt3">

    <input type="text" size="2" maxlength="3" name="item_3" class="txt2"><input
    type="hidden" name="Weight_3" value="60">
    <input type="hidden" name="Name_3" value="Chair, Arm"></td>

    <input type="text" size="2" maxlength="3" name="item_4" class="txt2"><input
    type="hidden" name="Weight_4" value="40">
    <input type="hidden" name="Name_4" value="Chair Rocker (wood)"></td>


    my php script
    <?
    $FTGGI_name = $_POST['GI_name'];
    $FTGGI_resphone = $_POST['GI_resphone'];
    $FTGGI_email = $_POST['GI_email'];
    $FTGGI_busphone = $_POST['GI_busphone'];
    for($i=2;$i<166;$i++){
    $FTGName[$i] = $_POST["item_$i"] * $_POST["Weight_$i"];
    $FTGtotal += $FTGName[$i];
    }
    $to = "com";
    $subject = "Estimation Request";
    $body = "Customer Name : $FTGGI_name\n"
    . "Customer Residence Phone: $FTGGI_resphone\n"
    . "Customer Email: $FTGGI_email\n"
    . "Customer Business Phone: $FTGGI_busphone\n"
    for($i=2;$i<166;$i++){
    .. "$_POST["name_$i"] . " : " . $FTGName[$i] . "\n" ";
    }
    . "Total is $FTGtotal\n";

    ?>


    ozgur Guest

Similar Threads

  1. Arrays (combine two arrays)
    By RonFusion in forum Coldfusion - Getting Started
    Replies: 11
    Last Post: May 2nd, 09:35 PM
  2. Nesting Arrays within arrays.
    By JimmySlam in forum Macromedia Flash Ad Development
    Replies: 3
    Last Post: March 15th, 09:42 AM
  3. [PHP] help with arrays
    By Chris W. Parker in forum PHP Development
    Replies: 3
    Last Post: September 23rd, 09:54 PM
  4. help with arrays
    By Chris W. Parker in forum PHP Development
    Replies: 3
    Last Post: September 23rd, 09:07 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139