Forms

when i submit a form in yii, according to the data typed, how to fetch the details from database

You pass $model to the form and that fetches the data automatically. (As seen in case of an update).

For example:

function actionFetchData()

{

$model = Page::model()->findByPk(‘1’);

$this->render("form", array(

      'model' => $model,


     ));

}

Here’s how your form looks like:

<?php echo $form->textField($model,‘name’); ?>

Hope i’ve understood your question right :)

Thanks.

[size="2"][color="#1c2837"]

In Controller Write These Code

function action<view>()

{

&#036;idTemp=&#036;GET['&lt;QueryStringName&gt;'];//Here Put name of Query String passed in parameter


&#036;model = Page::model()-&gt;findByPk(&#036;idTemp);//fetch Recodes


&#036;this-&gt;render(&quot;form&quot;, array('model' =&gt; &#036;model,)); //show in View

}[/color][/size]

These are my tables…

CREATE TABLE IF NOT EXISTS employee_master (

user_id int(10) NOT NULL,

first_name  varchar(50) NOT NULL,

blood_group int(10) NOT NULL,

PRIMARY KEY ( user_id )

) ;

CREATE TABLE IF NOT EXISTS blood_request (

id int(10) NOT NULL AUTO_INCREMENT,

user_id int(10) NOT NULL,

blood_group int(10) NOT NULL,

PRIMARY KEY ( id ),

FOREIGN KEY (user_id) REFERENCES employee_master(user_id)

) ;

In my form,

 i hav a text field for blood_group.. When i enter O+ve in the field, i want this data to be stored in blood_group column in blood_request table and then display all the first_name from employee_master table who has O+ve blood group...

Thanks

I suggest you go through some basic learning resources and then you should be able to do all this yourself.

You can also create a an operation using CRUD(Using the Gii module). When CRUD is used it’ll automatically generate the form and controller for you. You then can alter those files for according to your needs.

Create models for employee_master and blood_group (If you have database level relations defined Gii model generator will create the relations for you in the model) and then create a CRUD that will create the view/form and the controller for operating on that.

Thanks.

I tried… M not getting… can u send me the code

What code? You want me to write the whole code for you? :) Please go through the tutorials, be patient and steady and soon you’ll get a hang of it.

Thanks.