我有一个日历,每天都有一个像这样的复选框:
<input type="hidden" name="uevent['.$urange.']['.$list_day.']['.$month.']['.$year.']" value="0"><input type="checkbox" id="calendarcheck" name="uevent['.$urange.']['.$list_day.']['.$month.']['.$year.']" checked>$list_day
其中$ urange是三种日历中的一种。
当点击提交时,我想每天在mysql中存储是否被检查。所以我生成了这段代码:
print_r($_POST);
$big_query='INSERT INTO `sdcheckings` (`email`,`urange`,`cyear`,`cmonth`,`cday`,`dchecked`,`tcheck`) VALUES ';
for($i=0;$i<count($_POST[$row[0]]);$i++)
{
for($j=0;$j<count($_POST[$row[0]][$i]);$j++)
{
for($k=0;$k<count($_POST[$row[0]][$i][$j]);$k++)
{
if($k!=0)
$big_query.=', ';
$dchecked = $_POST[$row[0]][$i][$j][$k];
$big_query.='('.$_SESSION['email'].', '.$row[0].', '.$i.', '.$j.', '.$k.', '.$dchecked.', CURRENT_TIMESTAMP) ';
}
}
}
$adddates = mysql_query($big_query);
当我通过查看几个日期(2016年2月4日和2016年12月12日)进行测试时,我得到以下信息:
数组([uevent] =&gt;数组([1] =&gt;数组([4] =&gt;数组([02] =&gt; 数组([2016] =&gt;开)[3] =&gt;数组([2016] =&gt; 0))[5] =&gt;阵列( [02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[6] =&gt; 数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0)) [7] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[8] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组( [2016] =&gt; 0))[9] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt; 数组([2016] =&gt; 0))[10] =&gt;数组([02] =&gt;数组([2016] =&gt; 0) [3] =&gt;数组([2016] =&gt; 0))[11] =&gt;数组([02] =&gt;数组([2016] =&GT; 0)[3] =&gt;数组([2016] =&gt; 0))[12] =&gt;数组([02] =&gt;数组([2016] =&gt;开)[3] =&gt;数组([2016] =&gt; 0))[13] =&gt;数组([02] =&gt; 数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[14] =&gt;阵列( [02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[15] =&gt; 数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0)) [16] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[17] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组( [2016] =&gt; 0))[18] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt; 数组([2016] =&gt; 0))[19] =&gt;数组([02] =&gt;数组([2016] =&gt; 0) [3] =&gt;数组([2016] =&gt; 0))[20] =&gt;数组([02] =&gt;数组([2016] =&GT; 0)[3] =&gt;数组([2016] =&gt; 0))[21] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[22] =&gt;数组([02] =&gt; 数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[23] =&gt;阵列( [02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[24] =&gt; 数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0)) [25] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组([2016] =&gt; 0))[26] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt;数组( [2016] =&gt; 0))[27] =&gt;数组([02] =&gt;数组([2016] =&gt; 0)[3] =&gt; 数组([2016] =&gt; 0))[28] =&gt;数组([02] =&gt;数组([2016] =&gt; 0) [3] =&gt;数组([2016] =&gt; 0))[29] =&gt;数组([02] =&gt;数组([2016] =&GT; 0)[3] =&gt;数组([2016] =&gt; 0))[1] =&gt;数组([3] =&gt;数组([2016] =&gt; 0))[2] =&gt;数组([3] =&gt;数组([2016] =&gt; 0))[3] =&gt; 数组([3] =&gt;数组([2016] =&gt; 0))[30] =&gt;数组([3] =&gt;数组( [2016] =&gt; 0))[31] =&gt;数组([3] =&gt;数组([2016] =&gt; 0)))) [submit] =&gt;更新)
数据库没有存储任何内容。我怀疑我的循环不正确。怎么办?
在$ big_query结束时打印出来时,我得到了这个:
INSERT INTO `sdcheckings` (`email`,`urange`,`gender`,`cyear`,`cmonth`,`cday`,`dchecked`,`tcheck`) VALUES
答案 0 :(得分:0)
foreach($_POST['uevent'][$row[0]] as $yearnum => $postyear)
{
foreach($postyear as $monthnum => $postmonth)
{
foreach($postmonth as $daynum => $postday)
{
if($firstcoma>0)
$big_query.=', ';
$firstcoma++;
if(strcmp($postday,"on")==0)
$postday=1;
$big_query.='("'.$_SESSION['email'].'", '.$row[0].', "'.$row[1].'", '.$yearnum.', '.$monthnum.', '.$daynum.', '.$postday.', CURRENT_TIMESTAMP) ';
}
}
}