2014-02-22 1 views
1

그래서 다음과 같은 코드가 있습니다.HTML/PHP에서 확인란을 만드시겠습니까?

내 main.html 양식을 사용하면 값 (PC 가격)을 입력 할 수 있으며 제출하면 주어진 값/가격하에 모든 PC를 표시하는 pcs.php 스크립트를 호출합니다.

하지만 스크립트가 표시하는 정보 옆에 확인란이 있습니다. 즉

<br>alienware, 3000, gtx760 checkbox <br> asus rog, 2500, radeodhdxxxx checkbox <br> 

등등). pcs.php에서

//main.html

<BODY> 
<FORM METHOD="POST" ACTION="pcs.php" > 
    <INPUT TYPE='textbox' NAME='mypc' VALUE='' > 
    <INPUT TYPE="SUBMIT" NAME="Button" VALUE="Hit me"> 
    </FORM> </BODY> </HTML> 

//pcs.php

<?php 
$dd = $_POST['mypc']; 


$filename = "computer.txt"; 
$filepointer = fopen($filename,"r"); 
$myarray = file ($filename); 
for ($mycount = 0; $mycount < count($myarray); $mycount++) 
{   

    $apc = $myarray[$mycount]; 
    $price = getvalue($apc,1); 
    $part = explode(',', $apc); 
    //print $price ."<br>"; 
    //print $str ."<br>"; 
    if ($str <$dd) 
    { 
     for($pcount = 0; $pcount<3; $pcount++) { 
     print $part[$pcount] ."<br>"; 

    } 
    print "<br>"; 

} 


} 


function getvalue ($text, $commaToLookFor) 
{ 
$intoarray = explode(",",$text); 
    return $intoarray[ $commaToLookFor]; 
} 

// fclose ($filepointer); 


?> 


<p> 

</body> 
</html> 

// computer.txt 파일

alienware, 3000, gtx760<br> 
asus rog, 2500, radeonhdxxx<br> 
alienware, 5000, gtx titan<br> 
+0

정교하게 만드실 수 있습니까? – Toothbrush

+0

루프에'echo ""'를 추가하기 만하면됩니까? – Yani

답변

0

너는 modif 할 필요가있을거야. 당신은 체크 박스와 "script_to_post_to.php"체크 항목 목록에 응답 할 수있는 능력을 가진 각각의 요소와 형태를 가질 수 있습니다

// Create form 
print '<form method="post" action="script_to_post_to.php">';  

for ($mycount = 0; $mycount < count($myarray); $mycount++) {   
    $apc = $myarray[$mycount]; 
    $price = getvalue($apc,1); 
    $part = explode(',', $apc); 

    if ($str < $dd) { 
    for($pcount = 0; $pcount<3; $pcount++) { 
     print $part[$pcount] ."<br>"; 
    } 

    // Add checkbox and name with product type 
    print '<input type="checkbox" name="' . getvalue($apc, 2) . '" />'; 
    print "<br>"; 
    } 
} 

// Provide form submission button and close form element 
print '<input type="submit" value="Submit" />'; 
print '</form>'; 

: 예는 루프처럼 보일 수 있습니다.

+0

답변을 주셔서 감사합니다,하지만 지금은 또 다른 질문이 있습니다. 나는 체크 박스 배열을 만들고 싶었고, 체크 된 요소를 표시하고 싶다면 스크립트를 호출 할까? 나는 체크 박스의 이름을 다르게한다.하지만 배열에 만들면 그렇지 않다. – user2946804

관련 문제