0

你好编码员。我在将数据插入数据库时​​遇到问题,您能帮我处理一下控制器功能吗?这是我的php表单:

<form method='post' action='<?php echo site_url('a3_bus_system/output')?>'>
    <div class="_25">
        <strong>Route Name/Number</strong>
        <br/>
        <input type="text" name=""></input>
    </div>

        <p>&nbsp;<p>&nbsp;</p></p>

        <p>&nbsp;<p>&nbsp;</p></p>
        </p>

    <div id="div">

    </div>

  <p>&nbsp;</p><div class="_25">

    <p><input type="button" name="button" class="button red" id="button" value="Add"  onclick="generateRow() "/></a></p>
</div>
 <input type='button' value='Remove Button' id='removeButton'>

<p>&nbsp;</p><p>&nbsp;</p></div>

<input type="submit"  class="button blue" id="button" value="Register" />

</form> 
</div>


</div>

<div class="clear height-fix"></div>

        </div></div> <!--! end of #main-content -->
  </div> <!--! end of #main -->
 <script>
 var counter=1;
    function generateRow() {
    var count="<font color='red'>"+counter+"</font>";
   var temp ="  <p>&nbsp;&nbsp;&nbsp;&nbsp;<div class='_25'><input type='textbox' id='textbox' name='stop["+counter+"]' placeholder='Stop Name'></input></div>&nbsp;&nbsp;&nbsp;<div class='_25'><input type='textbox' id='textbox' name='timing["+counter+"]' placeholder='Timing'></input></div>&nbsp;<div class='_25'><select id='ampm' name='ampm["+counter+"]'><option>a.m</option><option>p.m</option></select>  </div>";

var newdiv = document.createElement('div');
newdiv.innerHTML = temp + count;

var yourDiv = document.getElementById('div');

yourDiv.appendChild(newdiv);
counter++;
    }
    </script>

这是我的控制器功能:

public function output()
    {
    $common['common']=$this->common;
    $this->load->helper('form');
    $this->load->database();


    foreach ($_POST['stop'] as $stopIndex => $stopValue) {

    if($stopValue!=NULL)
    {

    echo $stopIndex;
    echo $stopValue;

        }
    }
    foreach ($_POST['timing'] as $timingIndex => $timingValue)
    {
    if($timingValue!=NULL)
    {
    echo $stopValue['data'];
    }


}
foreach ($_POST['ampm'] as $ampmIndex => $ampmValue) {

  if($timingValue!=NULL)
    {
  echo $ampmValue;
  }
}

    $this->output->enable_profiler(TRUE);
    }   

这些是我的数据库字段:

route_number   stop_name   am_pm   timing

请给我一种插入查询以将所有这些输入字段发布到数据库中的方法。

4

2 回答 2

1

你有已经制作好的模型吗?在 Codeigniter 中,您应该使用模型进行所有直接的数据库活动。您需要了解的有关模型的所有信息都在此处进行了说明:http: //ellislab.com/codeigniter/user-guide/general/models.html

一旦在那里你会像这里解释的那样插入:http : //ellislab.com/codeigniter/user-guide/database/examples.html 尽管我总是使用活动记录类方式(http://ellislab.com/codeigniter/ user-guide/database/active_record.html),它更简单,抽象真的很有帮助。

于 2013-04-09T08:16:57.560 回答
0

您不能直接在数据库中发布数组...在插入之前序列化数据并在获取后反序列化

于 2013-04-09T11:26:44.930 回答