0
嗨,大家好我會在這裏總結我的問題,希望你能理解。PHP,Codeigniter:Foreach應該在控制器中訪問時回顯多行
主要目標:要有一個更改事件,這將取決於我在月訪問控制器並回顯多行或結果的選定值。
已經完成:我有一個更改事件在我的多重選擇將觸發我的控制器和訪問行。
上改變事件:
$('#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)
{
}
});
});
主要問題:
問題1:我的第一個問題是,當它呼應一排,數據更結果在選擇框外。
問題2:正如我在MySQL中試過我的查詢,它應該顯示至少2行,但它只顯示/回顯我的控制器內的foreach 1結果。
主代碼(控制器):
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
我已經試過了,但它會有一個未定義變量的錯誤:rows。 – Cecatrix
你需要在循環前設置$ rows ='' – Vickel
在你的方法中初始化它的第一行。看一看 –