duanjiang7505
2016-08-03 05:04
浏览 84
已采纳

从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

图片转代码服务由CSDN问答提供 功能建议

我使用二维数组从自定义字段输入值。 像这样

 &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; 
   
 
 

这是一个值为的循环 0更改为1,依此类推。 如果表单已提交,我想获取每个值。

  $ 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 ++; 
} 
   
 
 

怎么能 我将每个值存储在数据库

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpu3898 2016-08-03 05:48
    已采纳

    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);
    
    }
    
    点赞 评论

相关推荐 更多相似问题