Re: Question about arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/12/07, Jason Pruim <japruim@xxxxxxxxxx> wrote:
>
> Hi Everyone,
>
> I have a question, and to avoid getting flammed until the morning, I
> waited to ask until the end of my day :) Or near it at least.
>
> I have a small simple script I'm writing so that I can calculate how
> much a certain number of pieces weigh, The page can be seen here:
> HTTP://www.raoset.com/weight/
> and here is the php code:
>
> <?PHP
> //include 'defaults.php';
> include '../../media/debug.php';
> $pieceWeight = $_POST['txtWeight'];
> $pieceWeight = $pieceWeight /100;
> $Pieces = $_POST['txtPieces'];
> $weightOfRoute = $Pieces * $pieceWeight;
> $Route =strtoupper($_POST['txtRoute']);
> $TextBoxes = "2";//$_GET['txtNumber'];
>
> //$Vweight = $pieceWeight * $VtxtPieces;
> //Begin debugging
> echo "<BR>";
> var_dump($_POST);
> echo "<BR>";
> var_dump($_GET);
> echo "<BR>";
>
> //End Debugging
>
> $myArray = Array("Route" => "$Route", "Pieces" => $Pieces);//,
> "Record" =>$Record);
> //echo "<BR>myArray: ".$myArray["Route"]."<BR>";
>
> echo "<BR>";
> print_arr($myArray);
> echo "<BR>";
> //$VtxtRoute = strtoupper($_POST['txtRoute[]']);
> //$VtxtPieces1 = $_POST['txtPieces1'];
>
> //var_dump($Pieces, $weightOfRoute);
> //echo "<BR>Pieces[0]: $Pieces<BR>";
> $i = '0';
>
> echo <<<HTML
>        <form method='GET' action='index.php'>
>                <P></Number of text boxes needed: <input type='text'
> size='5'
> name='txtNumber' value='{$TextBoxes}'>
>        <input type='submit'></P>
>        </form>
>        <form method='POST' action='index.php'>
>        <P>Weight of 100 pieces: <input type='text' size='5'
> name='txtWeight'
> value='{$pieceWeight}'></p>
>        <table>
>        <tr>
>        <td>Route #</td>
>        <td>Pieces per route</td>
>        <td>Weight of route</td>
>        </tr>
> HTML;
>
>
> while($i < $TextBoxes) {
> //$arrRoute = array(txtRoute$i);
> //echo $arrRoute;
>        echo <<<HTML
>
>                <!--Begin display of text boxes -->
>                <tr>
>                        <td>
>                                <input type='text' size='5' name="txtRoute"
> value="{$myArray['Route']}">
>                        </td>
>                        <td>
>                                <input type='text' size='5'
> name='txtPieces'
> value="{$myArray['Pieces']}">
>                        </td>
>                        <td>
>                                {$weightOfRoute}#
>                        </td>
>                </tr>
>
> HTML;
>        $i++;
>
> }
> echo <<<HTML
>        </table>
>        <input type='submit'>
>        </form>
>
> HTML;
>
> /*
>        <tr>
>                <td>
>                        <input type='text' size='5' name='txtRoute2'>
>                </td>
>                <td>
>                        <input type='text' size='5' name='txtPieces2'>
>                </td>
>                <td>
>                        {$weightOfRoute}
>                </td>
>        </tr>
>        <tr>
>                <td>
>                        <input type='text' size='5' name='txtRoute3'>
>                </td>
>                <td>
>                        <input type='text' size='5' name='txtPieces3'>
>                </td>
>                <td>
>                        {$weightOfRoute}
>                </td>
>        </tr>
>        */
> ?>
>
> Obviously I have some debugging stuff listed in there, so that's not
> the end result that it WILL be :)
>
> What I'm having issues with is, it only takes the value of the second
> text box, it won't process my array. Anyone care to take a quick look?
> Or tell me other then the php website where to look? I've already
> looked there and just couldn't come up with anything that makes sense
> to me...
>
> Thanks for looking!
>
>
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> japruim@xxxxxxxxxx
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Jason,

You've duplicated the names of your text boxes, so the second ones overwrite
the first. I'd guess you want to create arrays using <input type='text'
size='5' name='txtPieces2[]'> instead of <input type='text' size='5'
name='txtPieces2'>.

hth,

-David.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux