views:

334

answers:

2

I refer to this page: http://stackoverflow.com/questions/1557273/jquery-post-array-of-multiple-checkbox-values-to-php

<input type="checkbox" class="box"  value="blue" title="A" />
<input type="checkbox" class="box"  value="red" title="B" />
<input type="checkbox" class="box"  value="white" title="C"/>

$('#include').click(function(){

    var val = $('.box:checked').map(function(i,n) {
        return $(n).val();
    }).get(); //get converts it to an array         

    var title = $('.box:checked').map(function(i,n) {
        return $(n).attr('title');
    }).get(); //get converts it to an array     

    $.post(url, {'val[]': val,'title[]':title}, function(response) {
        alert('scuess');
    });
        return false;
})
---------------------------------------------
<?php
   foreach($_GET['val'] as $numA)
   {
        foreach($_GET['title'] as $numB)
       {
            $str="insert into user_photos (val,title) values ('$numA','$numB')";
            mysql_query($str,$link); 
       }
   }
?>

Please tell me how to do that...

A: 
<input type="checkbox" class="box[A]" value="blue" />
<input type="checkbox" class="box[B]" value="red" />
<input type="checkbox" class="box[C]" value="white" />
<?
// load multi-dimensional array
$values = $_POST['box'];
foreach($values as $title) {
    foreach($title as $val) {
        // insert $title/$val into mySQL
    }
}
?>
A: 

do it this way...

jQuery

$('#include').click(function(){

    var data = $('.box:checked').map(function(i,n) {
        return {'val':$(n).val(), 'title': $(n).attr('title')};
    }).get(); //get converts it to an array         

    $.post(url, {'data': data}, function(response) {
        alert('scuess');
    });
        return false;
});

PHP

<?php
   foreach($_GET['data'] as $data)
   {
       $str="insert into user_photos (val,title) values ('$data[val]','$data[title]')";
       mysql_query($str,$link); 
   }
?>
Reigel
dearStill wrong...
I'm not a pro at PHP but try `print_r($_GET['data']);` to see what values are being sent to the server..
Reigel