PHP,Codeigniter:Foreach在控制器中访问时应回显多行

PHP,Codeigniter:Foreach在控制器中访问时应回显多行,php,html,codeigniter,foreach,Php,Html,Codeigniter,Foreach,大家好,我将在这里总结我的问题,希望你们能理解 主要目标:有一个“更改”事件,该事件将取决于我在当月选择的值,该值将访问控制器并回显多行或结果 已完成:我的多重选择中有一个on change事件,该事件将触发我的控制器并访问行 更改事件: $('#month').change(function() { var values = $(this).val(); // returns array // loop over values values.forEach(functio

大家好,我将在这里总结我的问题,希望你们能理解

主要目标:有一个“更改”事件,该事件将取决于我在当月选择的值,该值将访问控制器并回显多行或结果

已完成:我的多重选择中有一个on change事件,该事件将触发我的控制器并访问行

更改事件:

$('#month').change(function() {
  var values = $(this).val(); // returns array

    // loop over values
    values.forEach(function(val){

      if (val == 1)
      {
        $("#nomonthschoolfees").load(baseUrl+'/admin/summary/noMonthSchoolFees/'+studentId+'/'+schoolyearId);
      // This will access my controller if 1 is selected in multiple select.
      }
      else if (val == 2)
      {

      }
  });
});
public function noMonthSchoolFees($studentId = null, $schoolyearId = null)
{
    if ($studentId && $schoolyearId) {
        $studentfeesData = $this->model_feestudent->noMonthSchoolFees($studentId, $schoolyearId);

        if ($studentfeesData) {
            $arrayNumber = 0; 
            foreach($studentfeesData as $x => $studentfees) {
                $rows = '
                        <tr id="row'.$x.'" class="'.$arrayNumber.'">
                          <td class="form-group">
                            <select style="width: 400px; text-align-last:center;" class="form-control" name="subparticulars['.$x.']" id="subparticulars'.$x.'" readonly/>
                                <option value="'.$studentfees['feetype_id'].'"> '.$studentfees['feetype_name'].' </option>
                            </select>   
                          </td>
                          <td class="form-group">
                            <input type="text" class="form-control" name="subpaymentbalance[<?php echo $x; ?>]" id="subpaymentbalance<?php echo $x; ?>" onclick="copyBalance('.$x.')" style="text-align:center;" value="'.$studentfees['feestudent_amount'].'" readonly />
                          </td>
                        </tr>';
                $arrayNumber++;    
            }// end of foreach

        }// end of if ($studentfeesData)
    } // end of if ($studentId && $schoolyearId)

    echo $rows; // echo the results of rows.

}// end of function
主要问题:

问题1:我的第一个问题是,当它回显一行时,数据的结果在选择选项框之外

问题2:我在mysql中尝试了我的查询,它应该至少显示2行,但它只显示/回显了控制器中foreach的1个结果

表格和问题的屏幕截图:

主代码(控制器):

$('#month').change(function() {
  var values = $(this).val(); // returns array

    // loop over values
    values.forEach(function(val){

      if (val == 1)
      {
        $("#nomonthschoolfees").load(baseUrl+'/admin/summary/noMonthSchoolFees/'+studentId+'/'+schoolyearId);
      // This will access my controller if 1 is selected in multiple select.
      }
      else if (val == 2)
      {

      }
  });
});
public function noMonthSchoolFees($studentId = null, $schoolyearId = null)
{
    if ($studentId && $schoolyearId) {
        $studentfeesData = $this->model_feestudent->noMonthSchoolFees($studentId, $schoolyearId);

        if ($studentfeesData) {
            $arrayNumber = 0; 
            foreach($studentfeesData as $x => $studentfees) {
                $rows = '
                        <tr id="row'.$x.'" class="'.$arrayNumber.'">
                          <td class="form-group">
                            <select style="width: 400px; text-align-last:center;" class="form-control" name="subparticulars['.$x.']" id="subparticulars'.$x.'" readonly/>
                                <option value="'.$studentfees['feetype_id'].'"> '.$studentfees['feetype_name'].' </option>
                            </select>   
                          </td>
                          <td class="form-group">
                            <input type="text" class="form-control" name="subpaymentbalance[<?php echo $x; ?>]" id="subpaymentbalance<?php echo $x; ?>" onclick="copyBalance('.$x.')" style="text-align:center;" value="'.$studentfees['feestudent_amount'].'" readonly />
                          </td>
                        </tr>';
                $arrayNumber++;    
            }// end of foreach

        }// end of if ($studentfeesData)
    } // end of if ($studentId && $schoolyearId)

    echo $rows; // echo the results of rows.

}// end of function
公共函数noMonthSchoolFees($studentId=null,$schoolyearId=null)
{
如果($studentId&$schoolyearId){
$studentfeesData=$this->model_feesstudent->noMonthSchoolFees($studentId,$schoolyearId);
如果($studentfeesData){
$arrayNumber=0;
foreach($studentfeesData为$x=>$studentfees){
$rows=
“.$studentfees['feetype_name']”

您正在覆盖每个循环的
$rows

替换

...
$rows = '
    <tr id="row'.$x.'" class="'.$arrayNumber.'">
...
。。。
$rows=
...

公共函数noMonthSchoolFees($studentId=null,$schoolyearId=null)
{
$rows='';
...
$rows.='
...
同时修复结束标记(查看末尾的反斜杠):



您正在覆盖每个循环的
$rows

替换

...
$rows = '
    <tr id="row'.$x.'" class="'.$arrayNumber.'">
...
。。。
$rows=
...

公共函数noMonthSchoolFees($studentId=null,$schoolyearId=null)
{
$rows='';
...
$rows.='
...
同时修复结束标记(查看末尾的反斜杠):




我已经尝试过了,但是它会有一个未定义变量rows的错误。在方法中的循环初始化它的第一行之前,您需要设置$rows=''。请看一看,谢谢这一点,但是您知道第一个问题的解决方案是什么,因为它会导致在选择选项框外回显值?我的synt中出现了什么问题ax?您的“选择”上有一个反斜杠tag.看一看。我已经尝试过了,但是它会有一个未定义变量的错误:rows。在方法中的循环初始化它的第一行之前,您需要设置$rows=''。看一看OK谢谢这项工作,但是您知道第一个问题的解决方案是什么吗,因为它会导致在选择选项框外回显值?问题是什么在我的语法中?你的“选择”标签上有一个反斜杠。看一看。