so i needed to have a PHP / Jquery Checkbox sample that read and updated from MySQL db. combined a few different samples to come up with this guy…
checkboxes.php:
<?
// TRACK YOUR PHP IN FIRECONSOLE
// http://www.firephp.org/
require_once(‘../includes/FirePHP.class.php’);
require_once(‘../includes/fb.php’);
$firephp =& FirePHP::getInstance(true);
ob_start();
fb (“hello firePHP”);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title></title>
<script src=”http://code.jquery.com/jquery-latest.js”></script>
<script type=”text/javascript”>
$(function(){
$(‘.checkbox’).change(function(event){
checked_value = $(this).val();
if(this.checked)
{
//SHOW alert() COMMENT TO SEE value
alert(“[x] checked: ” + checked_value);
//do your PHP/MySQL Insert here via ajax…
$.ajax({
url: ‘login_feed_checked.php’,
type: ‘post’,
data: ‘feed_id=’ + checked_value,
success: function(result){
alert(result);
}
});
}
if( !this.checked )
{
//PHP/MySQL remove from DB
alert(“[ ] unchecked: ” + checked_value);
$.ajax({
url: ‘login_feed_unchecked.php’,
type: ‘post’,
data: ‘feed_id=’ + checked_value,
success: function(result){
alert(result);
}
});
}
});
$(‘#checkall’).change(function(){
$(‘.checkbox’).attr(‘checked’,$(this).attr(‘checked’))
});
});
</script>
</head>
<body>
<ul>
<li>
<input type=”checkbox” id=”cb1″ class=”checkbox” value=’a’ /><label for=”cb1″>A List Text</label>
</li>
<li>
<input type=”checkbox” id=”cb2″ class=”checkbox” value=’b’ /><label for=”cb2″>B List Text</label>
</li>
<li>
<input type=”checkbox” id=”cb3″ class=”checkbox” value=’c’ /><label for=”cb3″>C List Text</label>
</li>
<li>
<input type=”checkbox” id=”checkall” />check all
</li>
<ul>
</body>
</html>
login_feed_checked.php:
<?
require_once(‘../includes/FirePHP.class.php’);
require_once(‘../includes/fb.php’);
$firephp =& FirePHP::getInstance(true);
ob_start();
//fb (“login_feed_checked.php POST”);
//because you can’t see the echo in ajax call use FIREPHP
//echo “post: ” . $_POST[‘feed_id’];
//firePHP / fireBUG = rad!
fb(“CHECK POSTED: ” . $_POST[‘feed_id’]);
?>
login_feed_unchecked.php
<?
require_once(‘../includes/FirePHP.class.php’);
require_once(‘../includes/fb.php’);
$firephp =& FirePHP::getInstance(true);
ob_start();
//fb (“login_feed_unchecked.php POST”);
//because you can’t see the echo in ajax call use FIREPHP
//echo “post: ” . $_POST[‘feed_id’];
//firePHP / fireBUG = rad!
fb(“UNCHECK POSTED: ” . $_POST[‘feed_id’]);
?>