1

New to php, and sql. But here is the thing. I have a page that displays a table from a database, based on certain criteria. The table is loaded anytime I refresh the page. I am using this as a list of tasks for service.

I'va added a column with checkboxes for service-personell to mark everytime service has been done, ie. using this as a tasklist. But when u refresh page, or close browser to visit the page again, the checkboxes are listed as unchecked(of course)

I was just wondering how to maintain the status of checkboxes for a certain time? Maybe cookies? If so I need some guidance.

My php

{foreach ($list as $key => $row)
            {
                echo '<tr class="xcrud-row-' . $i . '"><td class ="check_row"><div><input type="checkbox" name="status" ></div></td>';
                if($this->is_numbers) echo '<td class="xcrud-num">' . ($key + $start + 1) . '</td>';}

Live example :

Here

Borreborst
  • 29
  • 2

2 Answers2

0

I think the best thing to do is update the database with an ajax call everytime a checkbox is clicked.

Ruben Serrate
  • 2,724
  • 1
  • 17
  • 21
0

The best way of doing it would be to store the checked/unchecked state for each user in the database. You can then use the checked attribute to modify the initial state of the checkbox, e.g.

<input name="selected-tasks" type="checkbox" checked="checked" />

Cookies would work, but apart from being messy, if someone used the site from a different browser they'd see different states of completeness.

You could turn the page into a form and do this via conventional POST, or use JavaScript to listen for a change of state on each checkbox, and then make an AJAX call to the back-end to update the database.

George Brighton
  • 5,131
  • 9
  • 27
  • 36
  • Hi George. Thank you for answering. I Have now made a boolean column in db, and its displayed as checkbox. Any example of how I could update the table with ajax? Pretty green here... – Borreborst Sep 12 '13 at 07:33
  • Bind an on change event to each checkbox, and use $.ajax() in the callback to send a (probably POST) request to your PHP code, which can update the database in the normal way. Your AJAX call will have to send some details about the checkbox so PHP knows which row to update. This should get you started: http://stackoverflow.com/questions/13365311/ajax-checkboxes-with-jquery-and-php :) – George Brighton Sep 12 '13 at 11:51