php dynamic variables from one webpage to another

Posted on 2004-11-16
Last Modified: 2008-03-06
Hi there.

I've got a problem with php. In one html page, I have a stock entry list where there is an dropdown box to state how many seperate items there are with some code lookin like this:
for ($indivstockitemscheck=1;$indivstockitemscheck<=$indivstockitems;$indivstockitemscheck++)

<td><font face="arial" size="2"><h3>Batch item #<?php echo $indivstockitemscheck; ?></h3></font></td>
<td><font face=arial size=2><b>Description:</b></td>
<td><input type="text" size=60 name="itemdesc<?php echo $indivstockitemscheck; ?>"></td>


This creates a list of variables like itemdesc1, itemdesc2, itemdesc3 as many itemdesc iterations as the user wishes.

This works fine.

The problem starts when the form is submitted to another php page that has to interpret the _POST variables.
I dont know how to assign variable names to the itemdesc range of variables, ie, this doesnt work:

while ($i<$noofitems)

Anyone got any ideas at all please?


Question by:daryn
    LVL 48

    Assisted Solution

    why not use

    Then $_POST["itemdesc"] will be an array automaticly (done by PHP) with that entred values
    LVL 6

    Accepted Solution

    ok, add this to the first page:

    <input type=hidden name=noItems value="<?PHP echo $indivstockitems; ?>">

    and for the second page:

    if ($noItems>0) {
    $itemArray=new Array();
    for ($i=0;$i<$noItems;$i++){

    echo "<pre>";
    echo "</pre>";


    Author Comment

    thanks very much, situation resolved.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now