Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP语法错误,意外';endforeach';(T_ENDFOREACH)_Php_Codeigniter - Fatal编程技术网

PHP语法错误,意外';endforeach';(T_ENDFOREACH)

PHP语法错误,意外';endforeach';(T_ENDFOREACH),php,codeigniter,Php,Codeigniter,我的代码怎么了 <?php foreach($query->result() AS $row);?> <tr> <td><?php echo $row->Qid?> </td> <td><?php echo $row->title?> </td> <td><?php echo $row->da

我的代码怎么了

 <?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;  ?>

错误消息:语法错误,意外的'endforeach'(T_endforeach) 使用Codeigniter更改代码:

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

您可以使用以下选项:

<?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 }  ?>

你应该使用
而不是

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

--------^
....

您的代码中有两个错误,分别是
foreach循环
echo

<?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;  ?>
///这里您需要使用:而不是;
//在这里你需要把;在结束标记之前?>
//在这里你需要把;在结束标记之前?>
//在这里你需要把;在结束标记之前?>

不要混淆
请确保您的模型在每次foreach之前返回
数据
错误
,并确保有任何有效数据要迭代。(
if(empty($data))…
)实际上不需要用
终止该行?>
<?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;  ?>