Trying to:
use data from an array, keeping it simple fruit, veggies, beer, that is used to generate the main value on a form that need to have two more user selected pieces of data attached to it. In the example there are only three main values, but in the requirements for the app, there can be up to 100 and the change based on the data source: i.e. this time food, next time cars, next time minerals etc. with the point being that the values and the number values change as needed. Once the user selects their values it is posted and the $_POST are is all good, but a mess to work with.
So.. set up a loop in a form:
<table border="1">
<tr>
//column headers here
</tr>
<?php
$parcedvaluesr=array();
$c=0;
foreach ($_SESSION['item_name'] as $value){
echo "<tr>";
{ ?>
<td>
<input type="text" value="<?php echo $value;?>"/>
<?php $header[$c]=$value;?> //gathers item_name put in session variable array later
</td>
<td>
<select name="10<?php echo $c;?>"> // assigns new name to each new row
<option value="old">old</options>
<option value="new">new</options>
<option value="rebuilt">rebuilt</options>
<option value="scrapped">scrapped</options>
</select>
</td>
<td>
<select name="20<?php echo $c;?>">// assigns new name to each new row
<option value="">blank
<option value="5">5</options>
<option value="6">7</options>
<option value="9">9</options>
<option value="10">10</options>
<option value="15">15</options>
<option value="20">20</options>
<option value="25">25</options>
<option value="30">30</options>
<option value="40">40</options>
<option value="50">50</options>
<option value="75">75</options>
<option value="100">100</options>
<option value="125">125</options>
<option value="150">150</options>
<option value="200">200</options>
<option value="255">255</options>
<option value="9,9">9,9</options>
</select>
</td>
<?php
}
echo "</tr>";
$c++;
}
Okay so all this works. It give you the item name , option drop down 1, and option drop down 2 all neatly in a table.
Since the item_name is just one set string it is put in an array, then set to a session variable and is all good, easy to loop through.
Array ( [0] => Shoes [1] => Sandles [2] => Sox ) this is the session headers
The post array is not so easy. Need to be able to loop through it to assign user input selected for each item_name to another place as say beer, new, 200 for all item_name.
An example of the post array during one "guess a fix" session was:
Array ( [post_for_table] => Create table [100] => INT [200] => [101] => INT [201] => [102] => INT [202] => ) this is the Post array
setting the index to a number did not work probably because it is being interpreted as a string not a number.
Need to be able to loop through the form input to dynamically generate useful data as item_name count is variable..
How do I set up:
1 the form better to so that options one can be stored in one array and options two in another
or
2 to parse the post array so you can loop through it to add both selected options to user response