Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not passing appropriate array information.

Status
Not open for further replies.

chadderbox

Technical User
Sep 9, 2012
2
0
0
US
Hello All,

I am working on retrieving and parsing some data from an API. I can get the data in and function it to an array. I can then display the data in a form. However, when I go to process from the form I am only returning the last array function instead of the desired response. Any ideas?


Here is the section, I am having troubles with.

** Note the information comes in from the API in a less than desirable format so I have to clean that before posting to my forms.

$info = array();

$byline = explode("\n", $data);
foreach ($byline as $i=> $value) {
if ($value !=""){
$info[] = $value ;
} }
if ($info !=""){
$number = array();
foreach ($info as $newdata){
$row = explode(",", $newdata);
$number[] = $row[0];
}

echo "<table style='border' cellspacing=0 cellpading=1>
<form method=POST action=numberfinal.php name = Number>
<input type=hidden name=CUST value=$CUST>
<tr><td width= 150 align=center><input readonly name=number value=$number[0]></td><td width=150 align=center>$rate</td><td>$CUST</td> <td><input type=submit value=Order name=Order></td></select>
</tr>
<tr><td width= 150 align=center><input readonly name=number value=$number[1]></td><td width=150 align=center>$rate</td><td>$CUST</td> <td><input type=submit value=Order name=Order></td></select>
</tr>
<tr><td width= 150 align=center><input readonly name=number value=$number[2]></td><td width=150 align=center>$rate</td><td>$CUST</td> <td><input type=submit value=Order name=Order></td></select>
</tr>
<tr><td width= 150 align=center><input readonly name=number value=$number[3]></td><td width=150 align=center>$rate</td><td>$CUST</td> <td><input type=submit value=Order name=Order></td></select>
</tr>
</table>";
 
To be more clear, no matter which submit I press (row 1 or row 4) the same number is passed through to my post. I would like to ensure that the appropriate number gets pass through, i.e. $number[0} or $number[4] depending on which submit is requested.
 
Adding random submit buttons does not in any way select what value to pass, specially since all your inputs are named the same, and belong to the same form. There's no way to uniquely identify the input you want because the submit buttons are in noay attached or linked to each input.


The easiest way to accomplish this would be to make separate forms for each input, so that each form and each button only submits one input.

Code:
foreach ($info as $newdata){
$row = explode(",", $newdata);
$number[] = $row[0];
}
foreach ([COLOR=#4E9A06][b]$number[/b][/color] as [COLOR=#204A87][b]$item[/b][/color])
{
echo "[COLOR=#A40000]<table style='border' cellspacing=0 cellpading=1> 
[COLOR=#000000][b]<form[/b][/color] method=POST action=numberfinal.php name = Number[COLOR=#000000][b]>[/b][/color]
<input type=hidden name=CUST value=$CUST>
<tr><td width= 150 align=center><input readonly name=number value=[COLOR=#204A87][b]$item[/b][/color]></td><td width=150 align=center>$rate</td><td>$CUST</td> <td><input type=submit value=Order name=Order></td> 
</tr> 
</table>[COLOR=#000000][b]</form>[/b][/color][/color]";
}


Alternatively you could use some Javascript, but I think that may be a little too complex.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top