[eluser]Timothy_[/eluser]
Hello fellow Codeigniter coders! :cheese:
Background Information
I have about 8 checkboxes that need to be updated in my mysql database.
I have a table with 4 fields (ID, project_id, checkbox_id, time_checked)
If an entry exists with a checkbox_id then that check box is 'checked'.
This works great, however the problem comes when I want to edit my checkboxes.
I did a quick and dirty which was basically to just delete all checkboxes with a certain project_id and then reinserting the values from the form.
This is now just not acceptable as I am keeping time references when each checkbox was checked and obviously this wont work if I am recreating them all from scratch.
So the question is...
How can I update only the fields that have been changed?
My friend helped me come up with the algorithm below.
Code:
if (empty($_POST['progresscheck'])) {
$linkproc = '';
}
else
{
$linkproc = $_POST['progresscheck'];
$N = count($linkproc);
for(int i=0; i<n; i++)
{
if($linkproc[$i] = checkedindatabase())
{
if($linkproc[$i] = notcheckedonpage)
{
removevalue(i)fromdatabase
}
}
else
{
//this means its not in database
if($linkproc[1] = checkedonpage)
{
insertINTOposition(i)indatabase
}
}
}
Unfortunately it's not quite there; and I really need some help to put the theory into real code.
I hope someone can help me with this.
Thanks,
Tim