我正在尝试在我的视图页面上找出我的复选框错误解析错误:语法错误,意外'如果'(T_IF)
我不确定该错误是什么以及如何修复它。
foreach ($user->result() as $row) {
echo '<tbody>';
echo '<tr>';
echo '<td class="text-center">' . if (in_array($row->user_id, $selected)) { .'</td>';
echo '<td class="text-center">' . form_checkbox(array('name' => 'selected[]', 'value' => $row->user_id, 'checked' => 'checked')) .'</td>';
echo } else {;
echo '<td class="text-center">' . form_checkbox(array('name' => 'selected[]', 'value' => $row->user_id)) .'</td>';
echo };
echo '<td class="text-center">' . $row->user_id .'</td>';
echo '<td class="text-center" style="font-weight: bolder;">' . $row->username .'</td>';
echo '<td class="text-center">' . ($row->status ? $this->lang->line('text_enabled') : $this->lang->line('text_disabled')) .'</td>';
echo '<td class="text-center">' . $row->date_added .'</td>';
echo '<td class="text-center">' . anchor("admin/users/edit/" . $row->user_id, '<div class="btn btn-primary text-right" role="button"><i class="fa fa-pencil"></i>
Edit</div>') .'</td>';
echo '</tr>';
echo '</tbody>';
}
答案 0 :(得分:0)
由于你在串联中使用if()
,你需要重构:
foreach ($user->result() as $row)
{
echo '<tbody>';
echo '<tr>';
if (in_array($row->user_id, $selected))
{
echo '<td class="text-center">' . form_checkbox(array('name' => 'selected[]', 'value' => $row->user_id, 'checked' => 'checked')) .'</td>';
}
else
{
echo '<td class="text-center">' . form_checkbox(array('name' => 'selected[]', 'value' => $row->user_id)) .'</td>';
}
echo '<td class="text-center">' . $row->user_id .'</td>';
echo '<td class="text-center" style="font-weight: bolder;">' . $row->username .'</td>';
echo '<td class="text-center">' . ($row->status ? $this->lang->line('text_enabled') : $this->lang->line('text_disabled')) .'</td>';
echo '<td class="text-center">' . $row->date_added .'</td>';
echo '<td class="text-center">' . anchor("admin/users/edit/" . $row->user_id, '<div class="btn btn-primary text-right" role="button"><i class="fa fa-pencil"></i> Edit</div>') .'</td>';
echo '</tr>';
echo '</tbody>';
}
答案 1 :(得分:0)
或多或少你应该更好地遵循这种方法。你不能连接echo / print中的if语句。
foreach ($user->result() as $row) {
$out = '<tbody>';
$out .= '<tr>';
$out .= '<td class="text-center">';
$out .='</td>';
if (in_array($row->user_id, $selected)) {
$out .= '<td class="text-center">' . form_checkbox(array('name' => 'selected[]', 'value' => $row->user_id, 'checked' => 'checked')) .'</td>';
}
else {
$out .= '<td class="text-center">' . form_checkbox(array('name' => 'selected[]', 'value' => $row->user_id)) .'</td>';
}
$out .= '<td class="text-center">' . $row->user_id .'</td>';
$out .= '<td class="text-center" style="font-weight: bolder;">' . $row->username .'</td>';
$out .= '<td class="text-center">' . ($row->status ? $this->lang->line('text_enabled') : $this->lang->line('text_disabled')) .'</td>';
$out .= '<td class="text-center">' . $row->date_added .'</td>';
$out .= '<td class="text-center">' . anchor("admin/users/edit/" . $row->user_id, '<div class="btn btn-primary text-right" role="button"><i class="fa fa-pencil"></i>
Edit</div>') .'</td>';
$out .= '</tr>';
$out .= '</tbody>';
}
echo $out;