Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should read more about AJAX calls, preferably with <code>.post()</code> function, and then update the data in database on the server side.</p> <p>Good luck.</p> <p>Based on the examples from <a href="http://api.jquery.com/jQuery.post/" rel="nofollow">the documentation of jQuery's .post()</a>, you can implement something like this (in JavaScript with jQuery):</p> <pre><code>var changeStatus = function(id){ $.post("updateState.php", { 'id': id } ); }; </code></pre> <p>and on the server side (eg. in updateState.php):</p> <pre><code>$id = (int)$_POST['id']; // here make some query using $id to update the state // in a manner you prefer </code></pre> <p><strong>EDIT:</strong></p> <p>But I would prefer something like that:</p> <p>1) on server side, displaying the checkbox (notice different quotes and <code>(int)</code> cast):</p> <pre><code>echo '&lt;input type="checkbox" data-state-id="' . (int)$theid . '" /&gt;'; </code></pre> <p>2) somewhere in JavaScript (see <a href="http://jsfiddle.net/bYZBy/" rel="nofollow">jsfiddle</a> as a proof):</p> <pre><code>jQuery(main_container).delegate('input[type="checkbox"][data-state-id]', 'change', function(event){ jQuery.post('update_state.php', { 'id': jQuery(this).attr('data-state-id'), 'state': jQuery(this).is(':checked') }); }); </code></pre> <p>3) somewhere on server side (in <code>update_state.php</code>):</p> <pre><code>$id = (int)$_POST['id']; $state = (bool)$_POST['state']; $query = 'UPDATE `states` SET `state`="' . $state . '" WHERE `id`="' . $id . '";'; // here execute the query, obviously adjusted to your needs </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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