Welcome Guest, Not a member yet? Register   Sign In
help me please. Im a beginner
#1

[eluser]tunabelly14[/eluser]
Im new in CI so I follow the tutorial in this link. http://net.tutsplus.com/tutorials/php/co...er-basics/ . After I finished following the tutorial I got this error. "Parse error: syntax error, unexpected '<', expecting T_STRING or T_VARIABLE or '{' or '$' in /Applications/MAMP/htdocs/application/controllers/helloworld.php on line 7". I don't know how to debug this because CI is quite different in plain php. I hope you can help me solve this Thank you in advance.

//this is my code in helloworld.php
&lt;?php
class Helloworld extends Controller{
function index()
{
$this->load->model('helloworld_model');

$data['result'] = $this->helloworld_model-><span class="sql">getData</span>();
$data['page_title'] = "CI Hello World App!";

$this->load->view('helloworld_view',$data);
}
}
?&gt;


//this is my code in helloworld_view.php
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?=$page_title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php foreach($result as $row):?&gt;
<h3>&lt;?=$row->title?&gt;</h3>
<p>&lt;?=$row->text?&gt;</p>
<br />
&lt;?php endforeach;?&gt;
&lt;/body&gt;
&lt;/html&gt;

//this my code in helloworld_model.php
&lt;?php
class Helloworld_model extends Model {

function Helloworld_model()
{
// Call the Model constructor
parent::Model();
}

function getData()
{
//Query the data table for every record and row
$query = $this->db->get('data');

if ($query->num_rows() > 0)
{
//show_error('Database is empty!');
}else{
return $query->result();
}
}

}
?&gt;
#2

[eluser]theprodigy[/eluser]
First off, welcome to CodeIgniter.
Secondly, when you post code, please remember to use the code tags. It makes it much easier to read.

As for your problem, there error tells you exactly where the problem is:
Quote:Parse error: syntax error, unexpected ‘<’, expecting T_STRING or T_VARIABLE or ‘{’ or ‘$’ in /Applications/MAMP/htdocs/application/controllers/helloworld.php on line 7

Code:
$data[‘result’] = $this->helloworld_model-><span class=“sql”>[/b]getData[b]</span>();
(remove the opening and closing span tags).

And this isn't a codeigniter syntax issue, this is a PHP syntax issue ;-)
#3

[eluser]broswilli[/eluser]
<code>
$data[‘result’] = $this->helloworld_model->getData();
</code>

On the View simply do this
<code>
&lt;?php foreach($result as $row):?&gt;
<span class=“sql”>&lt;?php echo $row ?&gt;</span>
&lt;?php endforeach; ?&gt;
</code>
#4

[eluser]Nick_MyShuitings[/eluser]
@theprodigy.... fitting avatar image, although you toned down the sarcasm well... I love people posting wonderfully detailed error messages that direct you down to the exact line, mentioning the exact character, which only appears twice in the line... facepalm... we need to make a sticky thread about how to troubleshoot code.




Theme © iAndrew 2016 - Forum software by © MyBB