簡體   English   中英

在MySQL中使用多維數組存儲$ _POST

[英]Storing $_POST with multi-dimensional array in mysql

我有一個日歷,每天都有一個復選框,如下所示:

    <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年2月12日)進行測試時,得到以下信息:

Array([uevent] => Array([1] => Array([4] => Array([02] => Array([2016] => on))[3] => Array([2016] => 0 ))[5] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[6] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[7] =>數組([02] =>數組([2016] => 0)[3] => Array([2016] => 0))[8] => Array([02] => Array([2016] => 0)[3] => Array([2016] => 0))[9] = > Array([02] => Array([2016] => 0)[3] => Array([2016] => 0))[10] => Array([02] => Array([2016] = > 0)[3] =>數組([2016] => 0))[11] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] = > 0))[12] =>數組([02] =>數組([2016] => on)[3] =>數組([2016] => 0))[13] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[14] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[15] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[16 ] =>數組([02] =>數組([2016 ] => 0)[3] =>數組([2016] => 0))[17] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016 ] => 0))[18] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[19] =>數組([ 02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[20] =>數組([02] =>數組([2016] => 0)[ 3] =>數組([2016] => 0))[21] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0)) [22] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[23] =>數組([02] =>數組( [2016] => 0)[3] =>數組([2016] => 0))[24] =>數組([02] =>數組([2016] => 0)[3] =>數組( [2016] => 0))[25] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[26] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0))[27] =>數組([02] =>數組([2016] => 0 )[3] =>數組([2016] => 0))[28] =>數組([02] =>數組([2016] => 0)[3] =>數組([2016] => 0 ))[29] =>數組([02] =>數組([201 6] => 0)[3] =>數組([2016] => 0))[1] =>數組([3] =>數組([2016] => 0))[2] =>數組( [3] =>數組([2016] => 0))[3] =>數組([3] =>數組([2016] => 0))[30] =>數組([3] =>數組([2016] => 0))[31] =>數組([3] =>數組([2016] => 0)))))[提交] =>更新)

該數據庫未存儲任何內容。 我懷疑我的循環不正確。 那怎么辦?

在最后的$ big_query打印時,我得到的是:

INSERT INTO `sdcheckings` (`email`,`urange`,`gender`,`cyear`,`cmonth`,`cday`,`dchecked`,`tcheck`) VALUES
        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) ';
                }
            }
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM