1

I have a problem on my php code.I am a beginner in php programmng language.I am using codeigniter to do this.But,when i receive my data using php in controller makes this problem.It makes selectbox with only two elements on it. one is 'select nation' and another is '$'.c['Nation_name']. this works on html properly.But when i using it controller using ajax makes this problem.Please help me friends...

 echo"<select name='sel_PAdrs_nation'  
 value=".$sel_nation."onchange='state(this.value,'C')' 
 id='sel_PAdrs_nation'><option>Select Nation</option>
 <?php
 if(isset('$'.contentCoun)){
 foreach('$'.contentCoun as '$'.c){
 if('$'.c['Nation_id']=='$'.sel_nation){
        echo'<option selected='selected' 
 value='$'.c['Nation_id']>'$'.c['Nation_name']</option>';
    }
    else{
            print'<option value='$'.c['Nation_id']>'$'.c['Nation_name'] 
 </option>';
    } 
 }
 }
 ?></select>";
Suhail
  • 59
  • 7
  • 2
    Possible duplicate of [Can you put PHP inside PHP with echo?](https://stackoverflow.com/questions/15228026/can-you-put-php-inside-php-with-echo) – Nigel Ren Sep 09 '18 at 07:26

1 Answers1

0

Inside the PHP echo no more PHP code to be evaluated because PHP interprets your code in a single pass.

$tempfunc="state(this.value,'C')";
echo"<select name='sel_PAdrs_nation' onchange='".$tempFunc."' id='sel_PAdrs_nation'><option>Select Nation</option>";

 if(isset($contentCoun)){
    foreach($contentCoun as $c){
        if($c['Nation_id'] == $sel_nation){
    echo "<option selected='selected'value='".$c['Nation_id']."'>".$c['Nation_name']."</option>";
    }
    else{
     echo "<option value='".$c['Nation_id']."'>".$c['Nation_name']."</option>";
    } 
 }
 }
 echo "</select>";
Sachin
  • 789
  • 5
  • 18