Member 13935271 Ответов: 0

Одни и те же значения отображаются в разных полях ввода в форме yii2


Я использую фреймворк Yii2 с PHP.
У меня есть функция, которая принимает 3 параметра в качестве идентификатора, года и месяца. Он проверяет, существует ли запись в таблице. Если он не существует, то четыре поля, такие как OpeningBalance, TotalValueofLoanGiven, LoanRepaidUptilNow и TotalValueOfLoanOutstanding, имеют значение 0. В противном случае для полей задаются значения предыдущих месяцев.

Функция возвращает 4 значения, но все 4 значения отображаются в каждом входном сигнале.

public function actionGroupsavinginfo($id,$year,$month)
    {
        $group = Yii::$app->db->createCommand('SELECT count(*) 
 FROM `groupsavingdetails`, groupdetails
 where groupdetails.GroupId=groupsavingdetails.GroupId
 and groupsavingdetails.Year<='.$year.'
 and groupsavingdetails.Month<='.$month.'
 and groupsavingdetails.GroupId='.$id
	 )
						-&gt;queryScalar(); 
 

 $groupsavingdetails = Yii::$app->db->createCommand('SELECT * 
 FROM `groupsavingdetails`
where
  groupsavingdetails.Year<='.$year.'
 and groupsavingdetails.Month<='.$month.'
 and groupsavingdetails.GroupId='.$id
	 )
						-&gt;queryAll(); 

        if ($group == 0) {

               echo $groupsavingdetails['OpeningBalance']=$groupsavingdetails['TotalValueofLoanGiven']=$groupsavingdetails['LoanRepaidUptilNow']=$groupsavingdetails['TotalValueOfLoanOutstanding']=0;		
            }
         else {

            foreach($groupsavingdetails as $groupsavingdetails1)
			 {
			
			     $groupsaving_details['OpeningBalance'] = $groupsavingdetails1['ClosingBalance'];
				
				$groupsaving_details['TotalValueofLoanGiven']= $groupsavingdetails1['TotalValueofLoanGiven'];
				
				$groupsaving_details['LoanRepaidUptilNow']=$groupsavingdetails1['LoanRepaidUptilNow'];

				
				 $groupsaving_details['TotalValueOfLoanOutstanding']= $groupsavingdetails1['TotalValueOfLoanOutstanding'];
		
			}

			echo $groupsaving_details['OpeningBalance'];
			echo $groupsaving_details['TotalValueofLoanGiven'];
			echo $groupsaving_details['LoanRepaidUptilNow'];
			echo $groupsaving_details['TotalValueOfLoanOutstanding'];
	
        }
    }



В форме я вызвал этот метод и установил значения следующим образом:

<?= $form->field($model, 'Month',['enableAjaxValidation' => true])->dropDownList(['01'=>'January', '02' => 'February','03'=>'March','04'=>'April','05'=>'May','06'=>'June','07'=>'July','08'=>'August','09'=>'September','10'=>'October','11'=>'November','12'=>'December'], ['prompt'=>'Select Month','onChange'=>'
            

	$.post("index.php?r=groupsavingdetails/groupsavinginfo&id='.'"+$("select#groupsavingdetails-groupid").val()+"&year='.'"+$("input#groupsavingdetails-year").val()+"&month='.'"+$("select#groupsavingdetails-month").val(),function(data){
						
			$("input#groupsavingdetails-openingbalance").val(data);
						$("input#groupsavingdetails-totalvalueofloangiven").val(data);
						$("input#groupsavingdetails-loanrepaiduptilnow").val(data);
						$("input#groupsavingdetails-totalvalueofloanoutstanding").val(data);
	  
	  });	
	']) ?>


Что я уже пробовал:

I am using Yii2 framework with PHP.
I have a function which takes 3 parameters as id, year and month. It cheecks whether there exists a record in the table. If it does'nt exists, then four fields such as OpeningBalance, TotalValueofLoanGiven, LoanRepaidUptilNow and TotalValueOfLoanOutstanding are set to 0. Otherwise previous months values are set to the fields.

<pre>public function actionGroupsavinginfo($id,$year,$month)
    {
        $group = Yii::$app->db->createCommand('SELECT count(*) 
 FROM `groupsavingdetails`, groupdetails
 where groupdetails.GroupId=groupsavingdetails.GroupId
 and groupsavingdetails.Year<='.$year.'
 and groupsavingdetails.Month<='.$month.'
 and groupsavingdetails.GroupId='.$id
	 )
						-&gt;queryScalar(); 
 

 $groupsavingdetails = Yii::$app->db->createCommand('SELECT * 
 FROM `groupsavingdetails`
where
  groupsavingdetails.Year<='.$year.'
 and groupsavingdetails.Month<='.$month.'
 and groupsavingdetails.GroupId='.$id
	 )
						-&gt;queryAll(); 

        if ($group == 0) {

               echo $groupsavingdetails['OpeningBalance']=$groupsavingdetails['TotalValueofLoanGiven']=$groupsavingdetails['LoanRepaidUptilNow']=$groupsavingdetails['TotalValueOfLoanOutstanding']=0;		
            }
         else {

            foreach($groupsavingdetails as $groupsavingdetails1)
			 {
			
			     $groupsaving_details['OpeningBalance'] = $groupsavingdetails1['ClosingBalance'];
				
				$groupsaving_details['TotalValueofLoanGiven']= $groupsavingdetails1['TotalValueofLoanGiven'];
				
				$groupsaving_details['LoanRepaidUptilNow']=$groupsavingdetails1['LoanRepaidUptilNow'];

				
				 $groupsaving_details['TotalValueOfLoanOutstanding']= $groupsavingdetails1['TotalValueOfLoanOutstanding'];
		
			}

			echo $groupsaving_details['OpeningBalance'];
			echo $groupsaving_details['TotalValueofLoanGiven'];
			echo $groupsaving_details['LoanRepaidUptilNow'];
			echo $groupsaving_details['TotalValueOfLoanOutstanding'];
	
        }
    }



В форме я вызвал этот метод и установил значения следующим образом:

<?= $form->field($model, 'Month',['enableAjaxValidation' => true])->dropDownList(['01'=>'January', '02' => 'February','03'=>'March','04'=>'April','05'=>'May','06'=>'June','07'=>'July','08'=>'August','09'=>'September','10'=>'October','11'=>'November','12'=>'December'], ['prompt'=>'Select Month','onChange'=>'
            

	$.post("index.php?r=groupsavingdetails/groupsavinginfo&id='.'"+$("select#groupsavingdetails-groupid").val()+"&year='.'"+$("input#groupsavingdetails-year").val()+"&month='.'"+$("select#groupsavingdetails-month").val(),function(data){
						
			$("input#groupsavingdetails-openingbalance").val(data);
						$("input#groupsavingdetails-totalvalueofloangiven").val(data);
						$("input#groupsavingdetails-loanrepaiduptilnow").val(data);
						$("input#groupsavingdetails-totalvalueofloanoutstanding").val(data);
	  
	  });	
	']) ?>

Gerry Schmitz

$groupsaving_details[]

"Цель" (элемент) не изменяется во внутреннем цикле, в то время как "источник"? Может быть.

Member 13935271

Так что же делать?

0 Ответов