douwei4370 2015-12-30 19:06
浏览 5
已采纳

语法中出现意外的其他错误? [关闭]

I have the following code that keeps giving me an "unexpected else" error. Does anyone see something that I missed that is jacking with the syntax?

<?php
$salesman = json_decode($invoice['salesman'], true);
if(empty($salesman)){
  for($i = 1; $i <= 5; $i++) {
    echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>';
} else {
  foreach($salesman as $k => $v) {
    $i = $k+1;
    if($v == "checked" {
      echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'" checked/> '.$i.'<br>'; // if checked, check.
    } else {
      echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>'; // if not checked, don't check.
    }
  }
}
  • 写回答

1条回答 默认 最新

  • dongzhiyong8577 2015-12-30 19:07
    关注
    for($i = 1; $i <= 5; $i++){
                echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>';
    

    You are missing a } after the for loop.

    Corrected code:

    <?php
    $salesman = json_decode($invoice['salesman'], true);
    if (empty($salesman)){
        for($i = 1; $i <= 5; $i++){
            echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>';
        }
    } else {
        foreach($salesman as $k => $v){
            $i = $k+1;
            if ($v == "checked") {
                echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'" checked/> '.$i.'<br>'; // if checked, check.
            } else {
                echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>'; // if not checked, don't check.
            }
        }
    }
    

    You also missed a ')' after $v == "checked" in the if-condition. Fixed that for you too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 gki vendor hook
  • ¥15 centos7中sudo命令无法使用
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联