语法错误:意外的'。在Codeigniter中?

时间:2018-08-21 07:32:06

标签: php codeigniter

我有一个类似

的错误
  

类型:ParseError

     

消息:语法错误,意外的'。'

     

文件名:/opt/lampp/htdocs/cctv/application/views/edit_camera.php

我的错误在哪里?

<div style="margin-top: " class="form-group">
  <label>Terminal</label>
  <select class="form-control input-lg" id="required" name='id_terminal' data-placeholder="Pilih transaksi">
   <?php foreach ($get_camera as $cam) { 
     if ($cam->id_camera == $this->uri->segment(3)) {
       foreach ($terminal as $ter) { 
         if($ter->id_terminal == $cam->id_terminal) { ?>
           <?php echo "<option ".($cam->id_terminal == $ter->id_terminal ? ." selected='selected'".).">".$ter->nama_terminal."</option>" ?>
        <?php   }
       }
     } ?>
   <?php } ?>
  </select>
</div>

2 个答案:

答案 0 :(得分:0)

此行

<?php echo "<option ".($cam->id_terminal == $ter->id_terminal ? ." selected='selected'".).">".$ter->nama_terminal."</option>" ?>

应更改为

<?php echo "<option ".($cam->id_terminal == $ter->id_terminal ? " selected='selected'" : '').">".$ter->nama_terminal."</option>" ?>

您仅添加了过多的“。”进行字符串连接,并错过了三元运算符上的“:”。

答案 1 :(得分:0)

您应该尝试这种方式,串联字符串的方式存在问题:

<div style="margin-top: " class="form-group">
    <label>Terminal</label>
    <select class="form-control input-lg" id="required" name='id_terminal' data-placeholder="Pilih transaksi">
    <?php 
        foreach ($get_camera as $cam) { 
            if ($cam->id_camera == $this->uri->segment(3)) {
                foreach ($terminal as $ter) { 
                    if($ter->id_terminal == $cam->id_terminal) {
                        echo "<option ".($cam->id_terminal == $ter->id_terminal ? " selected='selected'":'').">".$ter->nama_terminal."</option>";
                     }
                }
            } 
        } 
    ?>
    </select>
</div>