Pagination not correctly working in search

Hi all,

 Am a newbie to YII, I have a problem in pagination, it is when i fill the search keyword and click on submit, correct results are displayed in the first page i have set the pagesize to 25, So when i click on next page or page 2 in pagination it takes all the records from the DB but it should take the record depending on the search condition. Here's my coding

Form:

<script>

function displayactive()

{

window.location=&quot;&lt;?php echo 'index.php?r=franchise_accounts/active' ?&gt;&quot;;

}

function displayinactive()

{

window.location=&quot;&lt;?php echo 'index.php?r=franchise_accounts/inactive' ?&gt;&quot;;

}

function displayall()

{

window.location=&quot;&lt;?php echo 'index.php?r=franchise_accounts/admin' ?&gt;&quot;;

}

</script>

<form method="POST" action="index.php?r=franchise_accounts/details" name="dtl" >

<input type="radio" name="status" value="Active" checked="checked" onclick="displayactive();"> Active

<input type="radio" name="status" value="Inactive" onclick="displayinactive();"> Inactive

<input type="radio" name="status" value="All" onclick="displayall();"> All

<input style="float:right" class="greenbutton" type="submit" name="submit" value="Search" >

<input style="float:right" type="text" name="fran_loc" id="fran_loc" value="">

</form>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

    'id'=&gt;'franchise-accounts-grid',


    'dataProvider'=&gt;&#036;model-&gt;search_active(),


    'summaryText'=&gt;'',

//‘filter’=>$model,

    'columns'=&gt;array(


            array('class'=&gt;'CLinkColumn',


                    'label'=&gt;'edit',


                    'imageUrl'=&gt;'images/edit.png',


                    'urlExpression'=&gt;'Yii::app()-&gt;createUrl(&quot;franchise_accounts/update&quot;, array(&quot;id&quot;=&gt;&#036;data-&gt;franchise_account_id))',


            ),


            'franchise_location_code:text:FRANCHISE LOCATION #',


            'franchise_location_name:text:FRANCHISE LOCATION',


            'first_name:text:FIRST NAME',


            'last_name:text:LAST NAME',


            'email_address_1:text:EMAIL',


           


            'addwords_account_number:text:ADWORDS CLIENT ID',


    ),

));

?>

Controller:

public function actionDetails()

{


    


	//if(isset(&#036;_POST['dtl']))


	//{


	//print_r(&#036;_POST);	


		//echo &#036;stat;


		//echo &#036;id;


		


    if(&#036;_POST['submit'])


	{


	


	


	       


		&#036;id = &#036;_POST['fran_loc'];


		&#036;stat = &#036;_POST['status'];


		if(&#036;stat=='All')


		{


		//echo 'ALL';


			&#036;model_details=new franchise_accounts('search_details');


			if(isset(&#036;_POST['dtl']))


			


		       


			&#036;model_details-&gt;attributes=&#036;_POST['dtl'];


			&#036;this-&gt;render('details',array(


				'model'=&gt;&#036;model_details,


			));


		}


		elseif(&#036;stat=='Active')


		{


		//echo 'Act'; 


			&#036;model_details=new franchise_accounts('search_details_active');


			if(isset(&#036;_POST['dtl']))


			


			&#036;model_details-&gt;attributes=&#036;_POST['dtl'];


			&#036;this-&gt;render('search_active',array(


				'model'=&gt;&#036;model_details,


			));


		}


		elseif(&#036;stat=='Inactive')


		{


		//echo 'Inac';


			&#036;model_details=new franchise_accounts('search_details_inactive');


			if(isset(&#036;_POST['dtl']))


			


			&#036;model_details-&gt;attributes=&#036;_GET['dtl'];


			&#036;this-&gt;render('search_inactive',array(


				'model'=&gt;&#036;model_details,


			));


		}


		else


		{


		  // echo 'hii';


				&#036;this-&gt;render('details',array(


				'model'=&gt;&#036;model_details,


			));


		}


	}else


		{


			&#036;model_details=new franchise_accounts('search_details');


			&#036;this-&gt;render('details',array(


				'model'=&gt;&#036;model_details,


			));


		}


	


}

Model:

public function search_details()

{


	// Warning: Please modify the following code to remove attributes that


	// should not be searched.





	&#036;criteria=new CDbCriteria;


	


	//&#036;criteria-&gt;together = true;


			


	&#036;criteria-&gt;addSearchCondition('franchise_location_name','%'.&#036;_POST['fran_loc'].'%',false);


	


	//&#036;criteria-&gt;compare('status');





	return new CActiveDataProvider('franchise_accounts', array(


		'criteria'=&gt;&#036;criteria,


        'pagination'=&gt;array(


               'pageSize'=&gt;25,


           ),


	));


}





public function search_details_active()


{


	// Warning: Please modify the following code to remove attributes that


	// should not be searched.





	&#036;criteria=new CDbCriteria;


	


	//&#036;criteria-&gt;together = true;


	


	


	&#036;criteria-&gt;addSearchCondition('franchise_location_name','%'.&#036;_POST['fran_loc'].'%',false);


	


	&#036;criteria-&gt;compare('status',1);





	return new CActiveDataProvider('franchise_accounts', array(


		'criteria'=&gt;&#036;criteria,


        'pagination'=&gt;array(


               'pageSize'=&gt;25,


           ),


	));


}





public function search_details_inactive()


{


	// Warning: Please modify the following code to remove attributes that


	// should not be searched.





	&#036;criteria=new CDbCriteria;


	


            


	//&#036;criteria-&gt;together = true;


	


	


	&#036;criteria-&gt;addSearchCondition('franchise_location_name','%'.&#036;_POST['fran_loc'].'%',false);


	


	&#036;criteria-&gt;compare('status',0);


            





	return new CActiveDataProvider('franchise_accounts', array(


		'criteria'=&gt;&#036;criteria,


        'pagination'=&gt;array(


               'pageSize'=&gt;25,


           ),


	));


}

I don’t know what am missing or doing mistake…Please help me!!!

Hello. It’s hard to read your code. Can you please edit your post and use appropriate styling?

View:

<script>

         function displayactive()


         {


            window.location=&quot;&lt;?php echo 'index.php?r=franchise_accounts/active' ?&gt;&quot;;


         }


         function displayinactive()


         {


           window.location=&quot;&lt;?php echo 'index.php?r=franchise_accounts/inactive' ?&gt;&quot;;


         }


         function displayall()


         {


           window.location=&quot;&lt;?php echo 'index.php?r=franchise_accounts/admin' ?&gt;&quot;;


         }

</script>

<form method="POST" action="index.php?r=franchise_accounts/details" name="dtl" >

   &lt;input type=&quot;radio&quot; name=&quot;status&quot; value=&quot;Active&quot; checked=&quot;checked&quot; onclick=&quot;displayactive();&quot;&gt; Active


   &lt;input type=&quot;radio&quot; name=&quot;status&quot; value=&quot;Inactive&quot; onclick=&quot;displayinactive();&quot;&gt; Inactive


   &lt;input type=&quot;radio&quot; name=&quot;status&quot; value=&quot;All&quot; onclick=&quot;displayall();&quot;&gt; All





   &lt;input style=&quot;float:right&quot; class=&quot;greenbutton&quot; type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Search&quot; &gt;


   &lt;input style=&quot;float:right&quot; type=&quot;text&quot; name=&quot;fran_loc&quot; id=&quot;fran_loc&quot; value=&quot;&quot;&gt;

</form>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

    'id'=&gt;'franchise-accounts-grid',


    'dataProvider'=&gt;&#036;model-&gt;search_active(),


    'summaryText'=&gt;'',


    //'filter'=&gt;&#036;model,





    'columns'=&gt;array(


            array('class'=&gt;'CLinkColumn',


                    'label'=&gt;'edit',


                    'imageUrl'=&gt;'images/edit.png',


                    'urlExpression'=&gt;'Yii::app()-&gt;createUrl(&quot;franchise_accounts/update&quot;, array(&quot;id&quot;=&gt;&#036;data-&gt;franchise_account_id))',


            ),


            'franchise_location_code:text:FRANCHISE LOCATION #',


            'franchise_location_name:text:FRANCHISE LOCATION',


            'first_name:text:FIRST NAME',


            'last_name:text:LAST NAME',


            'email_address_1:text:EMAIL',


           


            'addwords_account_number:text:ADWORDS CLIENT ID',


    ),

));

?>

I can`t see search_active() method in your $model,

I do not recommend adding new methods, it is best to use search () and add the properties and conditions for your query, is preferred rename form fields to be received in an array data type, this makes things much more:




CHtml::textField('TransactionValue[' . $strData . ']')