-1

私の問題は、phpで信頼できるカテゴリを作成する必要があることですが、txtファイルからオプションを取得してもらいたいのですが、両方を行う方法はありますか? アイデアは、最初のドロップダウン メニューで 1 つのカテゴリを選択し、次に 1 つのカテゴリを 2 番目に選択するというものですが、カテゴリを txt ファイルで変更できるようにしたいと考えています。お時間いただきありがとうございます。これは私が作ったもののアイデアです

<tr>
        <td height="67" align="right">ΚΑΤΗΓΟΡΙΑ</td>
        <td><label>
          <select name="ΚΑΤΗΓΟΡΙΑ" id="ΚΑΤΗΓΟΡΙΑ" class="update" >
            <option value="ΚΟΙΝΟΧΡΗΣΤΑ" selected="selected">ΚΟΙΝΟΧΡΗΣΤΑ</option>
            <option value="ΘΕΡΜΑΝΣΗ">ΘΕΡΜΑΝΣΗ</option>
            <option value="ΑΝΕΛΚΥΣΤΗΡΑΣ">ΑΝΕΛΚΥΣΤΗΡΑΣ</option>
            <option value="ΕΙΔΙΚΕΣΔΑΠΑΝΕΣ">ΕΙΔΙΚΕΣ ΔΑΠΑΝΕΣ</option>
            <option value="ΙΔΙΟΚΤΗΤΩΝ">ΙΔΙΟΚΤΗΤΩΝ</option>
            </select>
          <select name="ΚΑΤΗΓΟΡΙΑ2" id="ΚΑΤΗΓΟΡΙΑ2" class="update" disabled="disabled">
            <option value="ΘΥΡΩΡΟΣ" selected="selected">ΘΥΡΩΡΟΣ</option>
            <option value="ΕΙΔΗΚΑΘΑΡΙΟΤΗΤΑΣ" selected="selected">ΕΙΔΗ ΚΑΘΑΡΙΟΤΗΤΑΣ</option>
          </select>
        </label></td>
      </tr>
4

1 に答える 1

1

これを試してください: コードは自己説明できるように十分にコメントされています

<?php 
$list1 = file("/path/to/options1.txt");/// read the first options list file

$selectedOption = $list1[0]; // default selected value is the first option as written in the code snipet above

if( isset($_GET["option1"]) && !empty( $_GET["option1"] ) ) {
    $selectedOption = urldecode( $_GET["option1"] ) ; // if the user changed the selection we update the second list
}

$list2 = file("/path/to/{$selectedOption}.txt");/// read the second options file based on the first element in the first list (since it will be the default selected value)

$currentUrl = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
?>

<script type="text/javascript">
    function load(){
        location.href = "<?php echo "$currentUrl";?>" + "?option1=" + document.getElementById("option1").value ;
    }
</script>

<tr>
        <td height="67" align="right">ΚΑΤΗΓΟΡΙΑ</td>
        <td><label>
          <select name="option1" id="option1" class="update" onchange="javascript:load()" >
            <?php
            foreach( $list1 as $_ ){
                $selected = "";
                if( trim( $selectedOption == trim( $_ ) ) )
                    $selected = "selected=\"selected\"";
                echo "<option value=\"". urlencode( $_ ) ."\" $selected >$_</option>\n";
            }
        ?>
        </select>

      <select name="option2" id="option2" class="update">
        <?php
            $selected = "selected=\"selected\"";
            foreach( $list2 as $_ ){
                echo "<option value=\"". urlencode( $_ ) ."\" $selected >$_</option>\n";
                $selected = ""; // only the first element will be marked as selected
            }
        ?>
      </select>
    </label></td>
  </tr>
于 2013-04-03T14:44:37.310 に答える