how to convert classname to classid and store into DB in yii framework -


i developing application using yii framework, have 1 table called "studentinformation", have columns in table

 id  name   mothername   phone        classid   parentname      email  1.  xxxxx    asdf       9658741230     2         pqrs        xy@gmail.com  

and have 1 more table called classname table

 classid  classname     1.      class1     2.      class2     3.      class3 

i set classid foreign key,i trying upload excel files instead of filling forms. excel format data

 id  name   mothername   phone         classid    parentname      email  1.  xxxxx    asdf       9658741230     class1      pqrs      xy@gmail.com  

in above table gave classname instead od classid because user comfortable classname not classid need store classid database

in controller getting value excel file

    $newmodel->name=$data[0];         $newmodel->mothername=$data[1];         $newmodel->phone=$data[2];         //i getting classname instead of classid           $classname=$data[11];         //i need convert classname classid         $classdet = classdetails::model()->findall(array("condition"=>"classname=>'$classname'"));       foreach(classdet $val)       {              $classid[] = $val->classid;       }    $newmodel->classid = $classid[0]; 

i not getting correct output please me...

your condition wrong, docs findall wants following parameters:

  1. $condition (mixed)
  2. $params (array)

like suggested in comment try use:

$classdet = classdetails::model()->findbyattributes(array("classname"=>$classname)); 

and should work. code should this:

$newmodel->name=$data[0]; $newmodel->mothername=$data[1]; $newmodel->phone=$data[2]; $classname=$data[11]; $classdet = classdetails::model()->findbyattributes(array("classname"=>$classname)); $newmodel->classid = $classdet->classid; //save or show new model. 

you may want put in logic on happens if classname not found in database. don't know if valid scenario.

like this:

$newmodel->name=$data[0]; $newmodel->mothername=$data[1]; $newmodel->phone=$data[2]; $classname=$data[11]; $classdet = classdetails::model()->findbyattributes(array("classname"=>$classname)); $newmodel->classid = 0; if($classdet){     $newmodel->classid = $classdet->classid; } //save or show new model. 

this way $newmodel->classid set 0 default. if $classdet not null set proper value.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -