php
  • html
  • 2013-10-03 110 views 0 likes 
    0
    <HTML> 
    <HEAD> 
    <TITLE> <b> Select the colors you want </b> </TITLE> 
    </HEAD> 
    <BODY> 
    <FORM action="colortables.php" method='post'> 
    <p>Pick one or more of the colors: </p><br/> 
    <select name='bcolors[]' size=8 multiple> 
    <?php 
        $pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white' 'purple'); 
        foreach ($pickcolors as $colors) { 
        printf("<option value='%s'>%s", $colors, $colors); 
        } 
    ?> 
    </select> 
    <select name='tcolors[]' size=8 multiple> 
    <?php 
        $pickcolors2 = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple'); 
        foreach ($pickcolors2 as $colors) { 
        printf("<option value='%s'>%s", $colors, $colors); 
        } 
    ?> 
    </select> 
    <p><input type='submit' value='pick'></p> 
    </FORM> 
    </BODY> 
    </HTML> 
    

    所以我還是比較新的HTML這樣下去容易在我身上,我想上面的代碼把兩個簡單的盒子,在每個盒子8個色可選你可以提交一個乘法表 - esque的顏色和文字組合。出於某種原因,儘管這段代碼不管我選擇什麼文字顏色,但它說我沒有選擇任何東西。任何幫助將是巨大的如何在同一個PHP頁面實現兩個<選擇與<options>

    編輯:tcolors是文字的顏色和bcolors是背景顏色

    +0

    $ pickcolors = array('red','blue','green','yellow','orange','black','white''purple');丟失 - >「,」後「白」 – Ashish

    +0

    你試試這個print_r($ _ POST);在colortables.php頁面上? – Ashish

    回答

    0

    當你使用printf()你沒有關閉<option>標籤。同時修復,作爲@Ashish發現。

    <select name='bcolors[]' size=8 multiple> 
    <?php 
        $pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple'); 
        foreach ($pickcolors as $colors) { 
         echo "<option value='$colors'>$colors</option>"; 
        } 
    ?> 
    </select> 
    

    更換第二個select也像我上面提到的那個。

    0

    看起來你可以在兩個選擇框中使用相同的數組。

    你可能不喜歡

    <select name='bcolors[]' size=8 multiple> 
    <?php 
        $pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white','purple'); 
        foreach ($pickcolors as $colors) { 
        echo "<option value='".$colors."'>".$colors."</option>"; 
        } 
    ?> 
    </select> 
    
    <!-- second select box with same array --> 
    <select name='tcolors[]' size=8 multiple> 
    <?php 
        foreach ($pickcolors as $colors) { 
        echo "<option value='".$colors."'>".$colors."</option>"; 
        } 
    ?> 
    </select> 
    
    0

    你缺少'white' and 'purple'之間的逗號(,)在第一個數組

    ,並沒有關閉選項中環

    <HTML> 
    <HEAD> 
    <TITLE> <b> Select the colors you want </b> </TITLE> 
    </HEAD> 
    <BODY> 
    <FORM action="colortables.php" method='post'> 
    <p>Pick one or more of the colors: </p><br/> 
    <select name='bcolors[]' size=8 multiple> 
    <?php 
        $pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple'); 
        foreach ($pickcolors as $colors) { 
        printf("<option value='%s'>%s</option>", $colors, $colors); 
        } 
    ?> 
    </select> 
    <select name='tcolors[]' size=8 multiple> 
    <?php 
        $pickcolors2 = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple'); 
        foreach ($pickcolors2 as $colors) { 
        printf("<option value='%s'>%s</option>", $colors, $colors); 
        } 
    ?> 
    </select> 
    <p><input type='submit' value='pick'></p> 
    </FORM> 
    </BODY> 
    </HTML> 
    
    0
    <select name='bcolors[]' size=8 multiple> 
        <?php 
         $pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple'); 
         foreach ($pickcolors as $key1=>$value1) {?> 
         <option value="<?php echo $value1;?>"><?php echo $value1;?></option> 
        <?php } 
        ?> 
        </select> 
        <select name='tcolors[]' size=8 multiple> 
        <?php 
         $pickcolors2 = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple'); 
         foreach ($pickcolors2 as $keys=>$values) {?> 
    
        <option value="<?php echo $$values;?>"><?php echo $values;?></option> 
    
        <?php } 
        ?> 
        </select> 
    
    <inpu type="submit" name="submit" value="pick"> 
    
    相關問題