2013-10-02 192 views
0

如何選擇選擇標籤的期權價值,通過從文本文件閱讀它,下面是我的代碼,如何選擇選擇標籤的選項值?

文本文件: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,即使當我將它作爲優先級時。

+0

什麼部分代碼不工作? – Maximus2012

回答

0

也許我錯了這裏,但我認爲這個問題是$data[$y][0] == "PROJECT TITLE"是不正確的,所以$submissiontype仍然是不確定的,因此該應該永遠不會被選擇的選項。

難道你不應該比較$data[$y][0]"SUBMISSION TYPE"