Advanced Search

Results 1 to 5 of 5

Thread: Correct Syntax

  1. #1
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Correct Syntax

    Hi all, when trying to implement the php below:

    PHP Code:
    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.
    Last edited by john0611; 08-03-2009 at 10:42 AM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,627
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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:
    PHP Code:
    foreach ($urls as $key => $linkSet) {
        echo 

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

    to this:
    PHP Code:
    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++) is extremely helpful in finding this kind of mistake.
    Last edited by traq; 07-25-2009 at 02:54 AM.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  3. #3
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    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 Code:
    <?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>';
    }  

    ?>

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,627
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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)
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  5. The Following User Says Thank You to traq For This Useful Post:

    john0611 (08-03-2009)

  6. #5
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Hi Traq,

    Thanks for your help.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •