Re: Array questions...
| From: | Jim Lucas | Date: | Wed, 05 Mar 2008 22:32:26 +0000 |
| Subject: | Re: Array questions... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271056@lists.php.net to get a copy of this message | ||
I won't address the main issue of your question, since it looks like that has been solved. But I want to point out a few other things that might help you.
Follow along below...
Jason Pruim wrote:
So for some reason, arrays always mess me up... I don't know what it is, but it just hasn't clicked yet... So I'm sure this is a simple question for someone who knows and understands arrays :)
So with that being said here's the code I'm using:
$self = $_SERVER['PHP_SELF'];
$i="0";
if (isset($_GET['txtNum'])) {
$numBox= $_GET['txtNum'];
$_SESSION['num'] = $_GET['txtNum'];
}else{
here you need to make sure that $_SESSION['num'] exists.
If not you will get a E_NOTICE warning level error.
So, you should have this
} else if ( isset($_SESSION['num']) ) {
$numBox = $_SESSION['num'];
}
And then follow up the previous thing with this else statement
} else {
echo 'no "num" set';
// AND / OR
$numBox = 0;
}
Change this to "post" <-- spec says lower case on the value And, you could get rid of the echo and move it to the last line of the previous HEREDOC statementecho "store box variable". $_SESSION['num'];echo <<<HTML<form method="GET"> How many boxes? <input type="text" size="2" name="txtNum"> <BR> <input type="submit"></form>HTML;$NumArray= Array($_POST['txtNumArray[]']);echo <<<TABLE<P>Weight of 100 pieces: <input type="text" size="5" name="txtPieceWeight"></P> <table border="1"><tr><th>Route #</th><th>Pieces in route</th><th>Weight of route</th></tr> TABLE;echo "<form method=\"POST\" action=\"$self\">";
Here you would use just value="txtNumArray[{$i}]"while($i < $numBox){echo <<<HTML<tr> <td> <input type="text" size="5" name="txtNumArray[]"
value="txtNumArray[$i]">Here you would use just value="{$i}"
</td>
<td>
<input type="text" size="5" name="txtPiecesArray[]"
Here you would use just value="txtPiecesArray[{$i}]"
value="txtPiecesArray[$i]">Here you would use just value="{$i}"
</td>
<td>
<input type="text" size="5" name="txtWeightArray[]"
Here you would use just value="txtWeightArray[{$i}]"
value="txtWeightArray[$i]">Here you would use just value="{$i}"
The reason I would do the above, is to make sure that all three arrays are in sync.</td> </tr>HTML;$i++; } echo "<input type=\"submit\"></form>";
What I'm attempting to do, is grab the info out of txtNumArray[] and put it into the variable $numArray Sounds easy enough right? Well I've tried using $NumArray = Array($_POST['txtNumArray[]'); but that's not working... I've tried $NumArray = $_POST['txtNumArray[]']; which didn't work... and I've looked on the php manual, but they all assume you understand this stuff which I do not :) Anyone know what I'm doing wrong? Or could at least point me to some text like "Array's for Dummies"? :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim@raoset.com-- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare