Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: expecting ','?

  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    expecting ','?

    Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /Users/avertstaff/Sites/johns/test/display.php on line 14


    Code:
      {
      echo "<div class='entry'>" . $row['FirstName'] . ' ' . $row['LastName'] . "<br>" $row['page'] "</div>";
      }
    can someone please help?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Try
    PHP Code:
    echo "<div class=\"entry\">{$row['FirstName']}  {$row['LastName']} <br>{$row['page']}</div>"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    You missed out a couple of concatenating .

    PHP Code:
    <?php
      
    echo '<div class="entry">' $row['FirstName'] . ' ' $row['LastName'] . '<br>' $row['page'] . '</div>';
    As pointed out in your previous question you need to use a . to concatenate (join) a string together.
    Also use ' instead of " around strings that contain html as they allow you to use " inside the tags.

  • #4
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    thanks, is there an easier way to write out php?

    can someone please help with the following statement I get the same error:

    Code:
    {
     echo '<div id="entry">' . '<div class="entry_header">' . "Name: " . $row['FirstName'] . ' ' . $row['LastName'] . '<br>' . "Page: " . '<a href='$row['page'] . '>'. $row['page'] . '</a>' . '</div>' . '</div>';
      }

  • #5
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Quickfix (note you don't need to concatenate each individual html tag, just when you are breaking from a string to a PHP variable):

    PHP Code:
    <?php
    echo '<div id="entry"><div class="entry_header">Name: ' $row['FirstName'] . ' ' $row['LastName'] . '<br />Page: <a href="' $row['page'] . '">'$row['page'] . '</a></div></div>';
    ?>
    One solution:

    PHP Code:
    <?php
    $output 
    '<div id="entry"><div class="entry_header">Name: ';
    $output .= $row['FirstName'] . ' ' $row['LastName'] . '<br />';
    $output .= 'Page: <a href="' $row['page'] . '">'$row['page'] . '</a>';
    $output .= '</div></div>';

    echo 
    $output;
    ?>
    Another solution using HEREDOC syntax:
    PHP Code:
    <?php
    $name 
    $row['FirstName'] . ' ' $row['LastName'];
    $page $row['page'];
    $output = <<<EOF
    <div id="entry">
      <div class="entry_header">
        Name: $name<br />
        Page: <a href="$page">$page</a>
      </div>
    </div>
    EOF;

    echo 
    $output;
    ?>
    Go here to find out all about strings.
    Last edited by RMcLeod; 05-14-2008 at 03:50 PM.

  • Users who have thanked RMcLeod for this post:

    jarv (05-14-2008)

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Quote Originally Posted by jarv View Post
    thanks, is there an easier way to write out php?

    PHP Code:
    <?php
    echo "<div id=\"entry\"><div class=\"entry_header\">Name: {$row['FirstName']} {$row['LastName']} Page: <a href=\"{$row['page']}\">{$row['page']}</a></div></div>";
     
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    jarv (05-14-2008)

  • #7
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by firepages View Post
    PHP Code:
    <?php
    echo "<div id=\"entry\"><div class=\"entry_header\">Name: {$row['FirstName']} {$row['LastName']} Page: <a href=\"{$row['page']}\">{$row['page']}</a></div></div>";
     
    ?>
    Whilst this certainly works, I wouldn't recommend using it, as it can be quite difficult to read when you come back to it, and can be quite difficult to locate where variables are as opposed to just string information. For large amounts of html I would highly recommend the HEREDOC syntax as you can easily read and write the html just as you would normally.

    Each to their own.
    Last edited by RMcLeod; 05-14-2008 at 04:04 PM.

  • #8
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    I am now trying to put a div outside of the repeated region {

    Code:
    $output = <<<EOF  
    <div id="entry">  
        {
    $name = $row['FirstName'] . ' ' . $row['LastName'];
    $page = $row['page'];
    
      <div class="entry_header">
        Assessor: $name<br />
        Page to be modified: <a href="http://www.avert.org/$page">$page</a> | <a href="http://cms.avert.org/webpages/edit/$page">edit page</a>
      </div>
    
    EOF;
    
    echo $output;
      }
    </div>
    my error is:
    Parse error: syntax error, unexpected T_SL in /Users/avertstaff/Sites/johns/test/display.php on line 18

  • #9
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    PHP Code:
    <?php
    echo '<div id="entry">';
     {
    $name $row['FirstName'] . ' ' $row['LastName'];
    $page $row['page'];

    $output = <<<EOF  
      
    <div class="entry_header">
        
    Assessor$name<br />
        
    Page to be modified: <a href="http://www.avert.org/$page">$page</a> | <a href="http://cms.avert.org/webpages/edit/$page">edit page</a>
      </
    div>
    EOF;

    echo 
    $output;
      }
    echo 
    '</div>';
    ?>
    You can't put PHP inside HEREDOC blocks apart from variable names. A HEREDOC block tells PHP that this is a string that should be output exactly as it is.

  • #10
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    that did not work, it says: Parse error: syntax error, unexpected T_SL in /Users/avertstaff/Sites/johns/test/display.php on line 23

    line 23 is:
    Code:
    $output = <<<EOF  
      <div class="entry_header">
        Assessor: $name<br />
        Page to be modified: <a href="http://www.avert.org/$page">$page</a> | <a href="http://cms.avert.org/webpages/edit/$page">edit page</a>
      </div>
    EOF;

  • #11
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    The problem is because the line EOF; has to be on it's own line with no whitespace (tabs or spaces) before or after it e.g.

    PHP Code:
    <?php
    //Works
    $output = <<<EOF
      <div class="entry_header">
        Assessor: $name<br />
        Page to be modified: <a href="http://www.avert.org/$page">$page</a> | <a href="http://cms.avert.org/webpages/edit/$page">edit page</a>
      </div>
    EOF;

    //Does Not Work
    $output = <<<EOF
      <div class="entry_header">
        Assessor: $name<br />
        Page to be modified: <a href="http://www.avert.org/$page">$page</a> | <a href="http://cms.avert.org/webpages/edit/$page">edit page</a>
      </div>
        EOF;
    ?>

  • #12
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    thanks, I changed it now it says: Parse error: syntax error, unexpected $end in /Users/avertstaff/Sites/johns/test/display.php on line 41

    line 41 is:
    Code:
    ?>

  • #13
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    You've missed a closing curly brace } somewhere in your code. Ensure all loops, if statements etc are properly closed with an ending }

  • #14
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Quote Originally Posted by RMcLeod View Post
    Whilst this certainly works, I wouldn't recommend using it, as it can be quite difficult to read when you come back to it, and can be quite difficult to locate where variables are as opposed to just string information. For large amounts of html I would highly recommend the HEREDOC syntax as you can easily read and write the html just as you would normally.

    Each to their own.
    from the confusion caused so far it would appear to be far easier
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #15
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    I also agree, and I had posted the first reply in that form.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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