Checkboxes from string stored in mysql
<p>I am working on a system whereby a user is given a choice of 7 checkboxes - each representing a day of the week.</p>

<p>If they tick M,T,W,T,F then I insert 12345 into the database as a string - if they choose W,T,F,S,S I insert 34567 into the database and so on. The insert is all working fine.</p>

<p>When I then retrieve the data from the database I am struggling to show them which days they currently have chosen. I have taken the data from the database and exploded it into individual items and then have a foreach loop but I am not sure what to do with it next:</p>

<pre><code>$wdays_array = str_split($wdays);

foreach($wdays_array as $day) {
 // do something here
}
</code></pre>

<p>Further down I then have HTML code which I use to insert in the first place which I need to change to checked if the value is set when they come back to modify their choices:</p>

<pre><code>&lt;ul&gt;
 &lt;li&gt;&lt;input type="checkbox" name="wdays[]" value="1"/&gt; &lt;label&gt;Monday&lt;/label&gt;&lt;/li&gt;
 &lt;li&gt;&lt;input type="checkbox" name="wdays[]" value="2"/&gt; &lt;label&gt;Tuesday&lt;/label&gt;&lt;/li&gt;
 &lt;li&gt;&lt;input type="checkbox" name="wdays[]" value="3"/&gt; &lt;label&gt;Wednesday&lt;/label&gt;&lt;/li&gt;
 &lt;li&gt;&lt;input type="checkbox" name="wdays[]" value="4"/&gt; &lt;label&gt;Thursday&lt;/label&gt;&lt;/li&gt;
 &lt;li&gt;&lt;input type="checkbox" name="wdays[]" value="5"/&gt; &lt;label&gt;Friday&lt;/label&gt;&lt;/li&gt;
 &lt;li&gt;&lt;input type="checkbox" name="wdays[]" value="6"/&gt; &lt;label&gt;Saturday&lt;/label&gt;&lt;/li&gt;
 &lt;li&gt;&lt;input type="checkbox" name="wdays[]" value="7"/&gt; &lt;label&gt;Sunday&lt;/label&gt;&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>How do I ensure the correct checkboxes are checked when the user reloads the form based on what is currently in the field in MySQL?</p>

<p>Thanks</p>
