Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make these fields autopopulate from the database?
    text
    copied!<p>I have an array, which holds values like this:</p> <pre><code>$items_pool = Array ( [0] =&gt; Array ( [id] =&gt; 1 [quantity] =&gt; 1 ) [1] =&gt; Array ( [id] =&gt; 2 [quantity] =&gt; 1 ) [2] =&gt; Array ( [id] =&gt; 72 [quantity] =&gt; 6 ) [3] =&gt; Array ( [id] =&gt; 4 [quantity] =&gt; 1 ) [4] =&gt; Array ( [id] =&gt; 5 [quantity] =&gt; 1 ) [5] =&gt; Array ( [id] =&gt; 7 [quantity] =&gt; 1 ) [6] =&gt; Array ( [id] =&gt; 8 [quantity] =&gt; 1 ) [7] =&gt; Array ( [id] =&gt; 9 [quantity] =&gt; 1 ) [8] =&gt; Array ( [id] =&gt; 19 [quantity] =&gt; 1 ) [9] =&gt; Array ( [id] =&gt; 20 [quantity] =&gt; 1 ) [10] =&gt; Array ( [id] =&gt; 22 [quantity] =&gt; 1 ) [11] =&gt; Array ( [id] =&gt; 29 [quantity] =&gt; 0 ) ) </code></pre> <p>Next, I have a form that I am trying to populate. It loops through the item database, prints out all the possible items, and checks the ones that are already present in $items_pool.</p> <pre><code>&lt;?php foreach ($items['items_poolpackage']-&gt;result() as $item): ?&gt; &lt;input type="checkbox" name="measure[&lt;?=$item-&gt;id?&gt;][checkmark]" value="&lt;?=$item-&gt;id?&gt;"&gt; &lt;?php endforeach; ?&gt; </code></pre> <p>I know what logically I'm trying to accomplish here, but I can't figure out the programming.</p> <p>What I'm looking for, written loosely is something like this (not real code):</p> <p><code>&lt;input type="checkbox" name="measure[&lt;?=$item-&gt;id?&gt;][checkmark]" value="&lt;?=$item-&gt;id?&gt;" &lt;?php if ($items_pool['$item-&gt;id']) { echo "SELECTED"; } else { }?&gt;&gt;</code></p> <p>Specifically this conditional loop through the array, through all the key values (the ID) and if there's a match, the checkbox is selected.</p> <p><code>&lt;?php if ($items_pool['$item-&gt;id']) { echo "SELECTED"; } else { }?&gt;</code></p> <p>I understand from a loop structured like this that it may mean a lot of 'extra' processing.</p> <p><strong>TL;DR</strong> - I need to loop within the array, check for the key 'id', then print a string.</p>
 

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