Welcome Guest, Not a member yet? Register   Sign In
An uncaught Exception was encountered
#1

in CodeIgniter view i have this, 
<!DOCTYPE html>
<html>
<head><title></title>

</head>
<body>

<?php 
echo "<table>
<tr>
    <th>Date</th>
  <th>Name</th>
  <th>Age</th>
  <th>Address</th>
  <th>Contact No</th>
  <th>Description</th>
</tr>"
if (isset($records)) {
foreach ($records as $row ){
echo "<tr>";
echo "<td>". $row->Date. "</td>"; 
echo "<td>" . $row->Name. "</td>";
echo "<td>" . $row->Age. "</td>";
echo "<td>" . $row->Address. "</td>";
echo "<td>" . $row->ContactNo. "</td>";
echo "<td>" . $row->Description. "</td>";
echo "</tr>";
}
}
echo "</tbody>
</table>";
<?php endforeach ;?>
<?php else :?>
<?php endif;?>
</body>
</html>

I got error near if and foreach 

how to resolve this?
Reply
#2

You forgot a semicolon on the line before the if statement. See:

PHP Code:
</tr>"; // <--- add semi colon here
if (isset(
$records)) { 

But there are some lines of code which are unnecessary and some things you could do different.

PHP Code:
<!DOCTYPE html>
<
html>
<
head>
 
 <title></title>
</
head>
<
body>

<
table>
<
tr>
 
 <th>Date</th>
 
 <th>Name</th>
 
 <th>Age</th>
 
 <th>Address</th>
 
 <th>Contact No</th>
 
 <th>Description</th>
</
tr>
<?
php 
if (isset($records)) {
foreach (
$records as $row ){ ?>
<tr>
<td><?= $row->Date ?></td> 
<td><?= $row->Name ?></td>
<td><?= $row->Age ?></td>
<td><?= $row->Address ?></td>
<td><?= $row->ContactNo ?></td>
<td><?= $row->Description ?></td>
</tr>
<?php }
} else { 
?>
<tr>
<td colspan="6">No records found</td>
</tr>
<?php ?>
</table>
</body>
</html> 

Hope it helps!

-Roger
Reply




Theme © iAndrew 2016 - Forum software by © MyBB