Re: FOR, FOREACH, and Input Box Names
| From: | Jason Wong | Date: | Fri, 25 Apr 2003 20:38:39 +0000 |
| Subject: | Re: FOR, FOREACH, and Input Box Names | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145313@lists.php.net to get a copy of this message | ||
On Saturday 26 April 2003 04:10, Guru Geek wrote:
> I'm creating a table. The number of rows is based on a previous student
> entry. Students must submit how many courses they are currently taking
> (numberCourses). Once they submit that value, I want to draw a table.
> The amount of rows in this table must be equal to the amount of courses
> being taken. Taking 3 courses then you'll get a table with 3 rows.
> Each row will have two input boxes (creditBox and estimatedGrade). The
> rest of the program will work with these two values extensively. How
> can I individualize the name of each creditBox? That is to say, how can
> I keep the value entered inside the creditBox in row one seperate from
> the value entered inside the creditBox on line 4 (assuming there is a
> line 4). I use a FOR statement to draw my table based on the amount of
> courses being taken.
>
> Here's my code:
>
> for ($boxCreator=0; $boxCreator < $numberCourses; $boxCreator++)
> {
> echo '
> <tr>
> <td align="center">Course</td>
> <td align="center"><input type="text"
> name="creditBox" size="2"></td>
>
> <td align="center"><input type="text"
> name="estimatedGrade"
> size="2"></td>
> </tr>';
> }
There are numerous ways to do this, here's what I would do:
... name="course[$boxCreator][creditBox]" ...
... name="course[$boxCreator][estimatedGrade]" ...
When it comes to processing you can do something like:
foreach ($_POST['course'] as $course) {
echo $course['creditBox'];
echo $course['estimatedGrade'];
}
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
To lead people, you must follow behind.
-- Lao Tsu
*/