2013-02-23 2 views
0

프로젝트에 codeigniter를 사용하고 있습니다. html 측면에서, 나는 체크 된 것을 볼 수있는 3 개의 체크 박스를 가지고 데이터베이스에 값을 저장한다. 이제 값을 가져 와서 해당 확인란을 선택합니다.데이터베이스에서 가져온 값에 따라 올바른 확인란을 선택하십시오.

내 체크 박스는 내가 값이 값 경사가 데이터베이스에 저장됩니다, 경사와 입력 요소를 확인하는 경우 예를 들어, 그래서

<div class="span2"> 
    <label class="radio"> 
     <input class="attrInputs" type="radio" name="shoulder" value="flat"> 
     Flat 
    </label> 
    <img src="http://placehold.it/126x126/cbcbcb" class="push-top"> 
</div> 
<div class="span2"> 
    <label class="radio"> 
     <input class="attrInputs" type="radio" name="shoulder" value="regular"> 
     Regular 
    </label> 
    <img src="http://placehold.it/126x126/cbcbcb" class="push-top"> 
</div> 
<div class="span2 border-right"> 
    <label class="radio"> 
     <input class="attrInputs" type="radio" name="shoulder" value="sloped"> 
     Sloped 
    </label> 
    <img src="http://placehold.it/126x126/cbcbcb" class="push-top"> 
</div> 

다음과 같이있을 때의 그 확인 입력과의 사전로드에 사용자가 로그인 값이 경 사진

미리 감사드립니다!

+0

을 당신이 [HTML 양식]를 읽을 필요가 있다고 생각 (http://www.w3schools.com/html/html_forms.asp), [CodeIgniter의 데이터 입력] (http://ellislab.com/codeigniter/user-guide/database/active_record.html#insert) 및 [CodeIgniter의 양식 도우미] (http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html) – hohner

답변

1

컨트롤러없이 데이터를 반환하는 방법을 알려 드리겠습니다.이 기능의 기본 원리를 알려 드리겠습니다. 본질적으로 어깨의 가치를 확인하고 적절한 상자를 결정할 것입니다. 따라서 컨트롤러에서 데이터를보기와 같이 보내면 (다시 db 나 테이블이 어떻게 생겼는지 모릅니다.)

컨트롤러 :

$this->load->model('someModel'); 
//the following populates the formData variable with an array from your database. 
//I am going to assume you know how to do this. 
$data['formData'] = $this->someModel->getData(); 
$this->load->view('someView',$data); 

보기, 그것은 사용하기 쉽게 될 수있는 반면 CI의 양식 처리기에 난 그냥 예를 들어 코드를 사용합니다 그래서 필요는 없습니다 만들었습니다.

<div class="span2"> 
    <label class="radio"> 
     <input class="attrInputs" type="radio" name="shoulder" value="flat" 
     checked="<?=$formdata['shoulder'] == 'flat' ? 'checked' : '' ;?>"> 
     Flat 
    </label> 
    <img src="http://placehold.it/126x126/cbcbcb" class="push-top"> 
</div> 
<div class="span2"> 
    <label class="radio"> 
     <input class="attrInputs" type="radio" name="shoulder" value="regular" 
     checked="<?=$formdata['shoulder'] == 'regular' ? 'checked' : '' ;?>"> 
     Regular 
    </label> 
    <img src="http://placehold.it/126x126/cbcbcb" class="push-top"> 
</div> 
<div class="span2 border-right"> 
    <label class="radio"> 
     <input class="attrInputs" type="radio" name="shoulder" value="sloped" 
     checked="<?=$formdata['shoulder'] == 'sloped' ? 'checked' : '' ;?>"> 
     Sloped 
    </label> 
    <img src="http://placehold.it/126x126/cbcbcb" class="push-top"> 
</div> 

위 코드가 수행하는 작업은 검사 할 상자를 결정하기 위해 간단한 if 문을 사용하는 것입니다. 각각은 데이터베이스가 리턴 한 'shoulder'의 값이 체크 박스와 같은지 확인하고, 체크 된 값이 맞으면 체크하고, 그렇지 않으면 비워 둡니다.

는 또한 PHP는 shorttags을 사용하기 때문에 사람들은 당신의 서버에서 사용하지 않는 경우 읽기를 사용하거나 PHP 태그를 조정 중 하나를

checked="<?php echo ($formdata['shoulder'] == 'flat' ? 'checked' : '') ;?>" 
+0

고마워! 잘 작동했다. – edelweiss

관련 문제