2012-10-09 4 views
0

데이터베이스에서 생성 된 국가의 드롭 다운 목록이있는 양식이 있습니다. 값은 데이터베이스에 저장됩니다. 사용자가 값을 보거나 업데이트 할 수있는 옵션이 있습니다. 모든 폼 값을 업데이트하려면 데이터베이스에서 가져옵니다. 내가 필요한 것은 국가의 선택된 옵션을 업데이트하기 위해 폼을로드 할 때 드롭 다운이 데이터베이스에 저장되어야한다는 것입니다. 예 : 다음 드롭 다운 옵션 2에서 선택한 경우 데이터베이스에 삽입됩니다. 갱신시데이터베이스에서 선택한 옵션 값을 지정하십시오.

Dropdown: |option1|<selected> 
      |option2| 
      |option3| 

가 여기에이

Dropdown: |option1| 
      |option2|<selected> 
      |option3| 

처럼해야 내가 노력 코드입니다.

 $selected = $list["country_country_name"]; 

    <tr><td>Country</td><td><select onchange="getCountry(this.value);" name="country" id="country" ><?php foreach($query as $qry) { 
    print '<option value="'.$qry["country_country_name"].'"'; 
    if($qry["country_country_name"] == $selected) print'selected'; 
    print '>'.$qry["country_country_name"].'</option>'."\n";} ?> 
    </select></td></tr> 
+0

pls을 downvoted 사람은 내가 왜 내 질문을 분명히 할 수 있도록 그 이유를 말해 이유는 그 이유는 – Avinash

+0

왜 선택을 사용하지? 옵션 목록이 있습니까? 이 옵션을 사용하면 선택한 옵션을 가져올 수 있습니다. 예를 원하세요? –

+0

db에서 내 드롭 다운을 채우고 있습니다. 이것이 pls가 제공하는 것을 의미하는 것이 아닌 경우 예 : – Avinash

답변

0

$ selected = $ list [ "country_country_name"];

<tr><td>Country</td> 
<td> 
<select onchange="getCountry(this.value);" name="country" id="country" > 
<?php foreach($query as $qry) { 
    $sel = ''; 
    if($qry["country_country_name"] == $selected) 
    $sel = 'selected="selected"';   

    echo '<option value="'.$qry["country_country_name"].'" '.$sel.'>'.$qry["country_country_name"].'</option>'."\n"; 
    } ?> 
    </select> 
    <?php echo form_error('country'); ?> 
    </td> 
</tr> 
+0

덕분에 그 일을 – Avinash

1
<select id="list" name="list"> 
    <option value=""> Please Select </option> 
    <? 
     $list = array('1', 
         '2', 
         '3', 
         '4', 
         '5', 
         '6'); 

     while ($L = array_shift($list)) { 
      ?> 
       <option value="<?=$L?>" <? if($selected == $L){ echo 'selected="selected"'; }?> > 
        <?= $L ?> 
       </option> 
      <? 
     } 
    ?> 
</select> 

할 수 있습니다 간단한 이와 선택한 옵션을 얻을 :

$("#list").val(); 

시도하시기 바랍니다.

+0

고마워. – Avinash

관련 문제