PHP 循环语法 回显选择时出错


PHP Loop Syntax Error echoing select

我有一个 3 个阶段的 if 语句

如果已经订购了项目,则回显

X,如果有人调用回显Y,则添加一个额外的字段来添加单个项目,然后jQuery在需要超过1个时添加更多 Z

我遇到的问题在 X 上,在订购带有一些选项的项目时有一个下拉菜单,这些选项只是硬编码,值 0,1,2,3,4 存储在数据库中,但显示为全文选项以保存存储比必要的更多信息只是更容易使用的数字然后显示值对应于它众所周知。但是,当我这样做时,即使没有语法错误,我也会在列表中为我存储的每个项目重复最后一个选项,它也使用下拉字段接管所有现有字段,没有下拉......代码跟随...

$mCount = 1;
if(isset($_POST['fDetails']) && is_array($_POST['fDetails']) && count($_POST['fDetails']) > 0){
    foreach($_POST['fDetails'] as $fDetail){
        if(!empty($fDetail['title']) || !empty($musicDetail['location'])){
echo('
<tr>
<th colspan="3"><label>Item '.$mCount.'</label></th>
</tr>
<tr>
<td colspan="1"><label for="fDetailTitle'.$mCount.'">Item Title:</label></td> 
<td colspan="2"><input type="text" size="25" name="fDetails['.$mCount.'][title]" value="'.$fDetail['title'].'" id="fDetailTitle'.$mCount.'" onKeyPress="return disableEnterKey(event)" />
</td>
</tr>
<tr>
<td colspan="1"><label for="fDetailArtist'.$mCount.'">Item location:</label></td>
<td colspan="2"><input type="text" size="25" name="fDetails['.$mCount.'][location]" value="'.$fDetail['location'].'" id="fDetailArtist'.$mCount.'" onKeyPress="return disableEnterKey(event)" />
</td>
</tr>
<tr>
<td colspan="1"><label for="fDetailitemStatus'.$mCount.'">item Status:</label></td>
<td colspan="2">
<select name="fDetails['.$mCount.'][arrange]" id="itemArrange'.$mCount.'" onKeyPress="return disableEnterKey(event)" >
<option value="0". $fDetail['arrange']=="Entry" ? 'selected="selected"':'' .'>Entry</option>
<option value="1". $fDetail['arrange']=="Exit" ? 'selected="selected"':'' .'>Exit</option> 
</select>
</td>
</tr>
<tr>
<td colspan="1"><label for="itemNotes'.$mCount.'">item Notes:</label></td>
<td colspan="2"><input type="text" size="25" name="fDetails['.$mCount.'][notes]" value="'.$fDetail['notes'].'" id="itemNotes'.$mCount.'" onKeyPress="return disableEnterKey(event)" /></td>
</tr>
<tr>'
);

任何人都可以看到问题吗?

上面添加的代码

您在这一行有错误:

 <option value="0". $fDetail['arrange']=="Entry" ? 'selected="selected"':'' .'>Entry</option>

我不知道你会怎么做,但''.'肯定是错误的。

看起来你在这两行上结束了你的字符串:

<option value="0". $fDetail['arrange']=="Entry" ? 'selected="selected"':'' .'>Entry</option>
<option value="1". $fDetail['arrange']=="Exit" ? 'selected="selected"':'' .'>Exit</option>

应该是...

<option value="0" '. $fDetail['arrange']=="Entry" ? 'selected="selected"':'' .'>Entry</option>
<option value="1" '. $fDetail['arrange']=="Exit" ? 'selected="selected"':'' .'>Exit</option>

我建议将其分解为较小的块而不是一个大字符串。