Welcome Guest, Not a member yet? Register   Sign In
Joining tables together in a model function
#9

[eluser]jpidgeon[/eluser]
I am running a select on the data table (even when it may be empty) as the data table populates my form fields, whereas the criteria table sets up how my form works and looks.

I've done it this way so I only have to use 1 foreach loop, rather than 1 inside another which I don't think is possible (I tried the other day and it didn't work correctly the way I did it)

This is part of my form view:

Code:
<?php $i = 0;  foreach($criteria as $item): ?>
<tr>    
        <td valign="top" class="criteria-column">
            <span class="criteria" id="criteria&lt;?php echo $item->criteria_order; ?&gt;">&lt;?php echo $item->criteria_name; ?&gt;</span>
            &lt;input name="qms_id[&lt;? echo $i; ?&gt;]" type="hidden"  value="&lt;?php echo $qms-&gt;qms_id; ?&gt;" />
            &lt;input name="data_id[&lt;? echo $i; ?&gt;]" type="hidden"  value="&lt;?php echo $item-&gt;data_id; ?&gt;" />
            &lt;input name="staff_id[&lt;? echo $i; ?&gt;]" type="hidden"  value="&lt;?php echo $qms-&gt;staff_id; ?&gt;" /></td>
        &lt;? if($count >= 1) { ?&gt;
        <td valign="top" class="kpi-column">
          &lt;?php if($item->criteria_kpi1 == "Y") { ?&gt;<select name="kpi1[&lt;? echo $i; ?&gt;]">
            <option value="NA" &lt;?php if (($item->kpi1) == "NA") {echo "selected=\"selected\"";} ?&gt;>NA</option>
            <option value="P" &lt;?php if (($item->kpi1) == "P") {echo "selected=\"selected\"";} ?&gt;>P</option>
            <option value="F" &lt;?php if (($item->kpi1) == "F") {echo "selected=\"selected\"";} ?&gt;>F</option>
  </select>&lt;? } ?&gt;</td>
        &lt;? } if($count >= 2) { ?&gt;
        <td valign="top" class="kpi-column">
          &lt;?php if($item->criteria_kpi2 == "Y") { ?&gt;<select name="kpi2[&lt;? echo $i; ?&gt;]">
            <option value="NA" &lt;?php if (($item->kpi2) == "NA") {echo "selected=\"selected\"";} ?&gt;>NA</option>
            <option value="P" &lt;?php if (($item->kpi2) == "P") {echo "selected=\"selected\"";} ?&gt;>P</option>
            <option value="F" &lt;?php if (($item->kpi2) == "F") {echo "selected=\"selected\"";} ?&gt;>F</option>
  </select>&lt;? } ?&gt;</td>
        &lt;? } if($count >= 3) { ?&gt;
        <td valign="top" class="kpi-column">
          &lt;?php if($item->criteria_kpi3 == "Y") { ?&gt;<select name="kpi3[&lt;? echo $i; ?&gt;]">
            <option value="NA" &lt;?php if (($item->kpi3) == "NA") {echo "selected=\"selected\"";} ?&gt;>NA</option>
            <option value="P" &lt;?php if (($item->kpi3) == "P") {echo "selected=\"selected\"";} ?&gt;>P</option>
            <option value="F" &lt;?php if (($item->kpi3) == "F") {echo "selected=\"selected\"";} ?&gt;>F</option>
  </select>&lt;? } ?&gt;</td>
        &lt;? } if($count >= 4) { ?&gt;
        <td valign="top" class="kpi-column colour-&lt;? echo $item->kpi4; ?&gt;">
          &lt;?php if($item->criteria_kpi4 == "Y") { ?&gt;<select name="kpi4[&lt;? echo $i; ?&gt;]">
            <option value="NA" &lt;?php if (($item->kpi4) == "NA") {echo "selected=\"selected\"";} ?&gt;>NA</option>
            <option value="P" &lt;?php if (($item->kpi4) == "P") {echo "selected=\"selected\"";} ?&gt;>P</option>
            <option value="F" &lt;?php if (($item->kpi4) == "F") {echo "selected=\"selected\"";} ?&gt;>F</option>
  </select>&lt;? } ?&gt;</td>&lt;? } ?&gt;
        <td valign="top">&lt;textarea value="" name="comments[&lt;? echo $i; ?&gt;]"&gt;&lt;?php echo $item->comments; ?&gt;&lt;/textarea&gt;&lt;/td>
          <td valign="top" class="edit-column">&lt;input &lt;?php if (!(strcmp("$item-&gt;develop","Y"))) {echo "checked=\"checked\"";} ?&gt; type="checkbox" name="development[&lt;? echo $i; ?&gt;]" value="Y"/></td>
</tr>
&lt;?php ++$i; endforeach; ?&gt;


Messages In This Thread
Joining tables together in a model function - by El Forum - 02-08-2011, 04:57 PM
Joining tables together in a model function - by El Forum - 02-08-2011, 09:26 PM
Joining tables together in a model function - by El Forum - 02-08-2011, 11:15 PM
Joining tables together in a model function - by El Forum - 02-09-2011, 06:25 AM
Joining tables together in a model function - by El Forum - 02-09-2011, 10:58 AM
Joining tables together in a model function - by El Forum - 02-09-2011, 11:57 AM
Joining tables together in a model function - by El Forum - 02-09-2011, 08:43 PM
Joining tables together in a model function - by El Forum - 02-09-2011, 08:53 PM
Joining tables together in a model function - by El Forum - 02-10-2011, 03:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB