CodeIgniter Forums
Parse error: syntax error, unexpected T_ECHO - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Parse error: syntax error, unexpected T_ECHO (/showthread.php?tid=43409)



Parse error: syntax error, unexpected T_ECHO - El Forum - 07-10-2011

[eluser]Mainboard[/eluser]
i have a little problem with codeigniter, in the view when i try to call some variables i have this problem, this is my code.

My View.

Code:
<? php foreach ($menu_enc as $menue): ?>
Code:
&lt;? '<a class="current">destino;'>' echo $menue->nombre_enc; '</a>' ?&gt;
Code:
&lt;?php endforeach; ?&gt;

i try with add echo at the start on the phrase like this

Code:
&lt;? echo '<a class="current">destino;'>' echo $menue->nombre_enc; '</a>'; ?&gt;

but not works, and i don't know why in the preview doesn't appear the href="'echo $menue->link;

so i what i can do? i know that is a some problem with the syntax but i can't find the correct syntax


Parse error: syntax error, unexpected T_ECHO - El Forum - 07-10-2011

[eluser]jmadsen[/eluser]
Thank you for moving your question over here.

CodeIgniter syntax is php syntax; you need to do things in the same way.

Code:
&lt;?php '<a class="current">destino;'>' echo $menue->nombre_enc; '</a>' ?&gt;

should read:

Code:
&lt;?php echo '<a class="current">' . $menue->nombre_enc . '</a>'; ?&gt;

I don't understand "destino" - is this the href="" part, and does it come from your database?

Grrr..the forum is making a mess of the html code!!

If $menue->destino is your href, then use:

Code:
href="    "
... put
Code:
'.$menue->destino.'
inside the quotes

----

Here are some more resources for understanding "concatenation":

An easy to read tutorial:
http://phphowto.blogspot.com/2006/12/concatenate-strings.html

The manual:
http://php.net/manual/en/language.operators.string.php


Parse error: syntax error, unexpected T_ECHO - El Forum - 07-11-2011

[eluser]Anonymous[/eluser]
This should work

Code:
&lt;?php
  foreach ($menu_enc as $menue):
    echo "<a href='' class='current'>destino $menue->nombre_enc </a>"; ?&gt;  
  endforeach;
?&gt;