?
Solved

php dynamic variables from one webpage to another

Posted on 2004-11-16
3
Medium Priority
?
165 Views
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:
<?php
for ($indivstockitemscheck=1;$indivstockitemscheck<=$indivstockitems;$indivstockitemscheck++)
{
?>

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

<?php
}
?>

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)
{
$itemdesc[$i]=$_POST["itemdesc$i"];
$i++;
}

Anyone got any ideas at all please?

thanks

Daryn
0
Comment
Question by:daryn
3 Comments
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 400 total points
ID: 12597567
why not use
name="itemdesc[]"

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

Accepted Solution

by:
mattjp88 earned 600 total points
ID: 12598137
ok, add this to the first page:

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

and for the second page:

<?PHP
$noItmes=$_POST['noItems'];
if ($noItems>0) {
$itemArray=new Array();
for ($i=0;$i<$noItems;$i++){
$itemArray[$i]=$_POST['itemdesc'.$i];
}
}

echo "<pre>";
print_r($itemArray);
echo "</pre>";

?>
0
 

Author Comment

by:daryn
ID: 12613725
thanks very much, situation resolved.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

579 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