PHP 语法错误,意外的“endforeach”(T_ENDFOREACH)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20919202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:40:15  来源:igfitidea点击:

PHP syntax error, unexpected 'endforeach' (T_ENDFOREACH)

phpcodeigniter

提问by Ahmad Nazirul

What's wrong with my code

我的代码有什么问题

 <?php foreach($query->result() AS $row);?>
      <tr>
         <td><?php echo $row->Qid?> </td>
         <td><?php echo $row->title?> </td>
         <td><?php echo $row->date?> </td>
      </tr>
 <?php endforeach;  ?>

Error message : syntax error, unexpected 'endforeach' (T_ENDFOREACH)using Codeigniter

错误消息:语法错误,使用Codeigniter 出现意外的“endforeach”(T_ENDFOREACH)

回答by Harshal Mahajan

change your code :

更改您的代码:

 <?php foreach($query->result() AS $row): ?>
change ; to :
change ; to :

OR

或者

you can use this :

你可以使用这个:

<?php foreach($query->result() AS $row){ ?>
   <tr>
     <td><?php echo $row->Qid?> </td>
     <td><?php echo $row->title?> </td>
     <td><?php echo $row->date?> </td>
   </tr>
<?php }  ?>

回答by Krish R

You should use :instead of ;

你应该使用:而不是;

<?php foreach($query->result() AS $row):?>
                               --------^
   ....
 <?php endforeach;  ?>

回答by Gopal

You are having two errors in your code, with foreach loopand with echo

您的代码中有两个错误, withforeach loop和 withecho

<?php foreach($query->result() AS $row):?>///here you need to use : instead of ;
  <tr>
     <td><?php echo $row->Qid; ?> </td> // here you need to put ; before  closing tag ?>
     <td><?php echo $row->title; ?> </td>// here you need to put ; before  closing tag ?>
     <td><?php echo $row->date; ?> </td>// here you need to put ; before  closing tag ?>
  </tr>
<?php endforeach;  ?>