Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think I understand your problem now. Your issue is that once you submit your form, this code runs: </p> <pre><code>foreach($engineer as $a =&gt; $b) { echo "| [[$engineer[$a]]] || ".getCellColor('mon')." | ..."; } </code></pre> <p>So, in other words, for each engineer you run the function getCellColor(); </p> <p>Now, the function getCellColor() also does a complete loop and evaluates all items posted, therefore, returning the result of your last form row. </p> <pre><code>function getCellColor($dow) { foreach($_POST[$dow . 'shifthours'] as $key=&gt; $hour) { ... } } </code></pre> <p>So, in other words, here is what is going on: </p> <ul> <li>foreach(engineer) loop starts </li> <li>foreach(engineer) gets engineer 1</li> <li>inside engineer 1, getCellColor starts</li> <li>getCellColor evaluates every single row and returns the value of the last row</li> <li>foreach(engineer) loops and gets engineer 2</li> <li>inside engineer 2, getCellColor starts</li> <li>getCellColor evaluates every single row and returns the value of the last row (again)</li> <li>... and so on</li> </ul> <p>Note: you say that the first line of output is correct, but actually it is NOT. Every line is outputting the result of the last line. </p> <p>As a suggestion, I would structure things something like Patrick Fisher mentioned in his answer. </p> <pre><code>&lt;select name="aa_1"&gt; &lt;select name="bb_1"&gt; &lt;input type="hidden" name="lines[]" value="1" /&gt; &lt;select name="aa_2"&gt; &lt;select name="bb_2"&gt; &lt;input type="hidden" name="lines[]" value="2" /&gt; &lt;select name="aa_3"&gt; &lt;select name="bb_3"&gt; &lt;input type="hidden" name="lines[]" value="3" /&gt; </code></pre> <p>That way, once you submit the form, you can get each form elements individually horizontally (i.e. line by line) and not vertically.</p> <pre><code>foreach($_POST["lines"] as $key =&gt; $value) { ${"aa_".$value} = $_POST["aa_".$value]; ${"bb_".$value} = $_POST["bb_".$value]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload