...

View Full Version : expecting ','?



jarv
05-14-2008, 01:43 PM
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /Users/avertstaff/Sites/johns/test/display.php on line 14




{
echo "<div class='entry'>" . $row['FirstName'] . ' ' . $row['LastName'] . "<br>" $row['page'] "</div>";
}



can someone please help?

abduraooft
05-14-2008, 01:46 PM
Try


echo "<div class=\"entry\">{$row['FirstName']} {$row['LastName']} <br>{$row['page']}</div>";

RMcLeod
05-14-2008, 01:46 PM
You missed out a couple of concatenating .



<?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.

jarv
05-14-2008, 02:34 PM
thanks, is there an easier way to write out php?

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



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

RMcLeod
05-14-2008, 02:48 PM
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
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
$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
$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. (http://uk.php.net/manual/en/language.types.string.php)

firepages
05-14-2008, 02:51 PM
thanks, is there an easier way to write out php?





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

RMcLeod
05-14-2008, 03:01 PM
<?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.

jarv
05-14-2008, 03:23 PM
I am now trying to put a div outside of the repeated region {



$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

RMcLeod
05-14-2008, 03:39 PM
<?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.

jarv
05-14-2008, 03:52 PM
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:
$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;

RMcLeod
05-14-2008, 04:07 PM
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
//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;
?>

jarv
05-14-2008, 04:11 PM
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:

?>

RMcLeod
05-14-2008, 04:26 PM
You've missed a closing curly brace } somewhere in your code. Ensure all loops, if statements etc are properly closed with an ending }

firepages
05-15-2008, 01:54 AM
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 ;)

abduraooft
05-15-2008, 07:45 AM
I also agree, and I had posted the first reply in that form. :)

jarv
05-15-2008, 08:45 AM
but i haven't touched the curly brace?!



<style type="text/css">
<!--
@import url("style.css");
-->
</style>
<?php
require('protectpage.php');
require('connection.php');


$result = mysql_query("SELECT * FROM assessment");

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

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>';


echo '<a href="insert.htm">Add new</a>';



mysql_close($link);
?>

RMcLeod
05-15-2008, 09:09 AM
The problem is that you have whitespace after EOF; Open the file in your editor place the cursor after EOF; hit your end key, this will take you to the end of any whitespace on that line, remove it all.

Also echo '<div id="entry">'; needs to appear before the while statement.

firepages
05-15-2008, 02:04 PM
I also agree, and I had posted the first reply in that form. :)

lol sorry abduraooft, managed to miss that somehow :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum