从wordpress中的二维数组中获取值
问题描述:
I am using a two dimensional array for inputting value from custom field. like this
<input type="text" name="education[0][edu_title]" placeholder="Title">
<input type="date" name="education[0][edu_to]" placeholder="To" class="calendar">
It is a loop that is value of 0 is changed to 1 and so on. Now if the form is submitted i want to get each value.
$tableedu = $wpdb->prefix . 'apply_edu';
$education=$pst_data['education'];
$sqldataedu = array();
$count=0;
foreach($education as $edu){
$sqldataedu['edu_title'] = stripslashes($edu[$count]['edu_title']);
$sqldataedu['edu_from'] = stripslashes($edu[$count]['edu_from']);
$sqldataedu['edu_to'] = stripslashes($edu[$count]['edu_to']);
$sqldataedu['edu_institute'] = stripslashes($edu[$count]['edu_institute']);
$sqldataedu['apply_id'] = $lastid;
$wpdb->insert($tableedu, $sqldataedu);
$count++;
}
how can i store each value in database
我使用二维数组从自定义字段输入值。 像这样 p>
&lt; input type =“text”name =“education [0] [edu_title]”placeholder =“Title”&gt;
&lt; input type =“ date“name =”education [0] [edu_to]“placeholder =”To“class =”calendar“&gt;
code> pre>
这是一个值为的循环 0更改为1,依此类推。
如果表单已提交,我想获取每个值。 p>
$ tableedu = $ wpdb-&gt; prefix。 'apply_edu';
$ education = $ pst_data ['education'];
$ sqldataedu = array();
$ count = 0;
foreach($ education as $ edu){
$ sqldataedu [' edu_title'] = stripslashes($ edu [$ count] ['edu_title']);
$ sqldataedu ['edu_from'] = stripslashes($ edu [$ count] ['edu_from']);
$ sqldataedu [' edu_to'] = stripslashes($ edu [$ count] ['edu_to']);
$ sqldataedu ['edu_institute'] = stripslashes($ edu [$ count] ['edu_institute']);
$ sqldataedu [' apply_id'] = $ lastid;
$ wpdb-&gt; insert($ tableedu,$ sqldataedu);
$ count ++;
}
code> pre>
怎么能 我将每个值存储在数据库 p>
div>中
答
Try this save data in database.
$education = $_POST['education'];
foreach( $education as $arr ){
$insert_data= array();
$insert_data['edu_title'] = stripslashes($arr['edu_title']);
$insert_data['edu_from'] = stripslashes($arr['edu_from']);
$insert_data['edu_to'] = stripslashes($arr['edu_to']);
$insert_data['edu_institute'] = stripslashes($arr['edu_institute']);
$insert_data['apply_id'] = $lastid;
$wpdb->insert($tableedu, $insert_data);
}