Log in

View Full Version : Resolved Correct Syntax



john0611
07-24-2009, 02:07 PM
Hi all, when trying to implement the php below:


foreach ($urls as $key => $linkSet) {
echo

'<a href="'.$linkSet[0].'"'.(($_SESSION['selectedLink'] == $key)?' selected="selected":'').'>'.$linkSet[1].'</a>;
}


I get this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\baturf\quotation_request.php on line 166

Any ideas I have tried to correct, but result ending up with more errors.

Thanks, John.

traq
07-25-2009, 02:47 AM
You've got an extra single-quote (after the ?) that needs to be removed, and you're missing one after the closing anchor tag. Change this:

foreach ($urls as $key => $linkSet) {
echo

'<a href="'.$linkSet[0].'"'.(($_SESSION['selectedLink'] == $key)?' selected="selected":'').'>'.$linkSet[1].'</a>;
}
to this:

foreach ($urls as $key => $linkSet) {
echo

'<a href="'.$linkSet[0].'"'.(($_SESSION['selectedLink'] == $key)? selected="selected":'').'>'.$linkSet[1].'</a>';
}
There might be more, but that's one thing I can see at a glance. If you don't already, using a text editor that highlights your code (like Notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm)) is extremely helpful in finding this kind of mistake.

john0611
07-25-2009, 06:50 PM
Hi trag,

Thanks for pointing those ones out.

After insterting the changes I get the following:

Parse error: syntax error, unexpected '=' in C:\wamp\www\baturf\include\btmnav.php on line 25

I've been trying to correct with dreamweaver, but to no avail.

Any other ideas?

Here is the full syntax.


<?php

$urls[] = array('linkURL1', 'linkName1');
$urls[] = array('linkURL2', 'linkName2');
$urls[] = array('linkURL3', 'linkName3');
$urls[] = array('linkURL4', 'linkName4');

?>

<?php

foreach ($urls as $key => $linkSet) {
echo

//below is the problem?
'<a href="'.$linkSet[0].'"'.(($_SESSION['selectedLink'] == $key)? selected="selected":'').'>'.$linkSet[1].'</a>';
}

?>

traq
07-26-2009, 12:10 AM
which line is line 25? Please post your entire page for more help.

Find that line and look for any "=", then you can try to figure out why it might be out-of-place.

On a side note, I stopped using web editors (e.g., Dreamweaver) because it is usually more difficult to put in handwritten code. A good text editor works best.

p.s., it's "traq" (Q, not G)

john0611
08-03-2009, 10:40 AM
Hi Traq,

Thanks for your help.