Welcome Guest, Not a member yet? Register   Sign In
error
#1

[eluser]davy_yg[/eluser]
Hello,

I have this codes:

Code:
<html>
<head>
<meta http-equiv="Content-Type" c charset=utf-8">
<title>untitled</title>
</head>
<body>
<h2>Create</h2>
&lt;?php echo form_open('site/create'); ?&gt;

<p>
  <label for="title">Title:</label>
  &lt;input type="text" name="title" id="title" &gt;
</p>

<p>
  <label for="content">Content</label>
  &lt;input type="text" name="content" id="content" /&gt;
</p>

<p>
  &lt;input type="submit" value="Submit" /&gt;
</p>
&lt;?php echo form_close(); ?&gt;

<h2>Read</h2>
&lt;?php if(isset($records)) : foreach($records as $row) : ?&gt;

<h2>&lt;?php echo $row->title; ?&gt;</h2>
<div>&lt;?php echo $row->content; ?&gt;</div>

<h2>No records were returned.</h2>

&lt;?php endif; ?&gt;

&lt;/form&gt;
&lt;/body&gt;


I get this error:


Parse error: syntax error, unexpected T_ENDIF in C:\xampp\htdocs\Codeigniter_213\application\views\options_view.php on line 34

Why is it?
#2

[eluser]boltsabre[/eluser]
You've got a shorthand foreach loop in there that you forgot to close and you've got your "no records" inside your if statement, you want something like this ;-)

Code:
&lt;?php if(isset($records)) : foreach($records as $row) : ?&gt;

<h2>&lt;?php echo $row->title; ?&gt;</h2>
<div>&lt;?php echo $row->content; ?&gt;</div>

<h2>No records were returned.</h2>

&lt;?php endif; ?&gt;

Should be:
&lt;?php if(isset($records)) :?&gt;
   &lt;?phpforeach($records as $row) : ?&gt;

    <h2>&lt;?php echo $row->title; ?&gt;</h2>
    <div>&lt;?php echo $row->content; ?&gt;</div>
   &lt;?php endforeach; ?&gt;
&lt;?php else:?&gt;
    <h2>No records were returned.</h2>
&lt;?php endif; ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB