如何选择select标签的选项值?

时间:2013-10-02 21:17:17

标签: php

如何选择select标签的选项值,通过从文本文件中读取,下面是我的代码,

文本文件:txt.txt

  SUBMISSION TYPE:PRIORITY

PHP:

  $filename = 'txt.txt';
  $str = file_get_contents($filename);

   $data = explode("\n", $str);  

   for ($z=0; $z<=1; $z++){
     $data[$z] = explode(":", $data[$z]);
       }
   for ($y=0; $y<=1;$y++){
   if($data[$y][0]=="SUBMISSION TYPE"){
   $submissiontype= $data[$y][1];} 
    }    

HTML:

     <th>Submission Type: <title="Submission Type"></th>

  <td><select id="submission" name="submission" autocomplete="off">
    <option value="NORMAL"<?php echo strcmp($submissiontype, 'NORMAL') === 0 ? ' selected' : ''; ?> >NORMAL</option>
 <option value="PRIORITY"<?php echo strcmp($submissiontype, 'PRIORITY') === 0 ? ' selected' : ''; ?>>PRIORITY</option>
 <option value="PAPERSTUDY"<?php echo strcmp($submissiontype, 'PAPERSTUDY') === 0 ? ' selected' : ''; ?>>PAPERSTUDY</option>
     </td>

有人能指出这段代码中的错误吗?

代码的HTML嵌入式PHP部分无法正常工作,提交类型值始终被选为NORMAL,即使我将其指定为PRIORITY。

1 个答案:

答案 0 :(得分:0)

也许我在这里错了,但我认为问题是$data[$y][0] == "PROJECT TITLE"永远不会成立,所以$submissiontype仍然未定义,因此选择的选项永远不会是

您不应该将$data[$y][0]"SUBMISSION TYPE"进行比较吗?