PHP两个foreach循环,内部foreach无法正常工作

时间:2013-11-14 22:13:21

标签: php

使用PHP构建的简单视图。我试图用内循环填充<option>标签。表单加载,但只有已为播放器选择的选项可见。其他人从未出现过。我用print_r确认$query_awards很好并填充:

<?php
//print_r($query_players);
print_r($query_awards);
foreach ($query_players as $row):
    echo "<form method=POST action=player_update><table><tr> <input type=hidden name=player_id value=".$row->id.">";
    echo "<td><input type=text name=first_name value=".$row->first_name."></td>";
    echo "<td><input type=text name=last_name value=".$row->last_name."></td>"; 
    echo "<td><input type=text name=school_name value='".$row->school_name."'></td>";
    echo "<td><select name=\"award_id\"><option selected value=".$row->award_id.">".$row->award_name."</option>";
    foreach ($query_awards as $award_row): // <-- Broken?
      "<option value=".$award_row->id.">".$award_row->name."</option></select></td>";
    endforeach;
    echo "<td><input type=submit name=submit value=Update></td>";

    echo "</tr></table></form>";
endforeach;
?>

令人讨厌的是,内循环中的</select>正在出现。

1 个答案:

答案 0 :(得分:3)

您忘记了行尾的echo

"<option value=".$award_row->id.">".$award_row->name."</option></select></td>";