How To Implement This Code In Yii

hello ,

i want to implement this code in yii…

Jquery and Html code is working fine in yii only storing in to db is not working

------------------------------ PHP Code ------------------

<?php

include ‘db.php’;

if(isset($_GET[‘save’]))

{

&#036;i=0;


while(&#036;_GET[&quot;skills_&#036;i&quot;])


{


    &#036;s=&#036;_GET[&quot;skills_&#036;i&quot;];


    &#036;u=&#036;_GET[&quot;used_&#036;i&quot;];


    &#036;mexp=&#036;_GET[&quot;mexp_&#036;i&quot;];


    &#036;yexp=&#036;_GET[&quot;yexp_&#036;i&quot;];


    &#036;q=mysql_query(&quot;insert into skills (skills,used,mexp,yexp) values('&#036;s',&#036;u,&#036;mexp,&#036;yexp)&quot;);


    &#036;i++;


}

}

?>

------------------------------ HTML Code ------------------

<html>

<head>

</head>

<body>

&lt;form name=&quot;skill&quot; action=&quot;kal.php&quot; method=&quot;get&quot; id=&quot;sk&quot;&gt;

<table border="0">

<th>Skills</th> <th> Used</th> <th> Experience</th> <th> Experience</th>

<tr class="table1" id="row0">

<td><select name="skills_0" id="skills_0"> <option value="">Select</option>

<?php

&#036;q=mysql_query(&quot;select SkillsId,SkillsName from bsskills&quot;);


while(&#036;row=mysql_fetch_array(&#036;q))


{


	echo &quot;&lt;option value=&quot;.&#036;row['SkillsId'].&quot;&gt;&quot;.&#036;row['SkillsName'].&quot;&lt;/option&gt;&quot;;


}

?>

</select>

</td>

<td><select name="used_0" id="used_0"> <option value="">Select</option>

<?php

&#036;q=mysql_query(&quot;select Completionyear from bsnumber&quot;);


while(&#036;row=mysql_fetch_array(&#036;q))


{


	echo &quot;&lt;option value=&quot;.&#036;row['Completionyear'].&quot;&gt;&quot;.&#036;row['Completionyear'].&quot;&lt;/option&gt;&quot;;


}

?>

</select>

</td>

<td><select name="mexp_0" id="mexp_0"> <option value="">Month</option>

<?php

&#036;q=mysql_query(&quot;select Completionyear from bsnumber&quot;);


while(&#036;row=mysql_fetch_array(&#036;q))


{


	echo &quot;&lt;option value=&quot;.&#036;row['Completionyear'].&quot;&gt;&quot;.&#036;row['Completionyear'].&quot;&lt;/option&gt;&quot;;


}

?>

</select>

</td>

<td><select name="yexp_0" id="yexp_0"> <option value="">Year</option>

<?php

&#036;q=mysql_query(&quot;select Completionyear from bsnumber&quot;);


while(&#036;row=mysql_fetch_array(&#036;q))


{


	echo &quot;&lt;option value=&quot;.&#036;row['Completionyear'].&quot;&gt;&quot;.&#036;row['Completionyear'].&quot;&lt;/option&gt;&quot;;


}

?>

</select>

</td>

</tr>

<tr><td colspan="2" align="center"><input type="button" value="Add" id="add"/><input type="button" value="Remove" id="rmv"/></td></tr>

<tr><td colspan="2" align="left"><input type="submit" value="save" name="save" id="save"/> </td></tr>

</table>

&lt;/form&gt;

</body>

</html>

----------------------------------- Jquery Code----------------------

<script src="jquery.js">

</script>

<script type="text/javascript">

      &#036;(document).ready(function() 


      {


          var num = &#036;('.table1').length-1; // how many &quot;duplicatable&quot; input fields we currently have


          var newNum = new Number(num + 1); 


          


          &#036;(&quot;#add&quot;).click(function()


          {


               var num_rows  = &#036;('.table1').length+1;


  		    &#036;(&quot;#table1_num_rows&quot;).val(num_rows);


                var num     = &#036;('.table1').length-1; // how many &quot;duplicatable&quot; input fields we currently have


                var newNum  = new Number(num + 1);      // the numeric ID of the new input field being added


            // create the new element via clone(), and manipulate it's ID using newNum value


            var newElem = &#036;('#row0').clone().attr('id', 'row' + newNum);





            newElem.children(':eq(0)').children(':eq(0)').attr('name', 'skills_' + newNum).attr('id', 'skills_' + newNum).attr('value','');


            newElem.children(':eq(1)').children(':eq(0)').attr('name', 'used_' + newNum).attr('id', 'used_' + newNum).attr('value','').append(&quot;&lt;option selected&gt;Select&lt;/option&gt;&quot;);


            newElem.children(':eq(2)').children(':eq(0)').attr('name', 'mexp_' + newNum).attr('id', 'mexp_' + newNum).attr('value','').append(&quot;&lt;option selected&gt;Select&lt;/option&gt;&quot;);


            newElem.children(':eq(3)').children(':eq(0)').attr('name', 'yexp_' + newNum).attr('id', 'yexp_' + newNum).attr('value','').append(&quot;&lt;option selected&gt;Select&lt;/option&gt;&quot;);


          


        // insert the new element after the last &quot;duplicatable&quot; input field


            &#036;('#row' + num).after(newElem);


            &#036;('#rmv').attr('disabled','');


       })


           


           if(&#036;('.table1').length == 1)


           {


                &#036;('#rmv').attr('disabled','disabled');


           }


           


           &#036;(&quot;#rmv&quot;).click(function()


           {


                var num = &#036;('.table1').length; 


                var num = num-1;


                &#036;('#row' + num).remove();     


                &#036;(&quot;#table1_num_rows&quot;).val(num);


                // if only one element remains, disable the &quot;remove&quot; button


                if (num == 1)


                    &#036;('#rmv').attr('disabled','disabled');


                });

})

</script>

i tried to implement but it’s not working…

Can you please suggest me which code where i have to put? :rolleyes: :unsure:

Replace the code


$q=mysql_query("insert into skills (skills,used,mexp,yexp) values('$s',$u,$mexp,$yexp)");

By




$q=Yii::app()->db->createCommand->execute("insert into skills (skills,used,mexp,yexp) values('$s',$u,$mexp,$yexp)");




I suggest plz go through Yii guide OR any Yii documentation/book as well as MVC structure.

Then move from Core to MVC/Yii.

thanks for replay…

which way i should implement that while loop in yii? there i am checking how many doprdown created by user’s. based on that i am isnerting in to DB.

i have created two projects in yii. but this situation came first time so i am bit confused :unsure:

una pregunta en el grupo "en español" deberia se escrita en español

please write in english…

Use model as




$values=Model::model()->findAll();

if($values){

 foreach($values as $value){

 // your code

}

}



Thanks all…

i got solution for this…

in controller i just checked condition

while(isset($POST['skill$i]))

{

saving all attributes here…

model()->save()

}

Again thanks :D

must work with MVC!

must work with Yii 100%

please read this document ! http://www.yiiframework.com/doc/guide/

the correct form of work with Yii

MVC !!!