Forum Moderators: coopster

Message Too Old, No Replies

Parse error: syntax error, unexpected T VARIABLE in

php error

         

dannj

4:22 am on Jul 14, 2007 (gmt 0)

10+ Year Member



hey guys ,
need help with this
i'm trying to get Alternating Row Colors into my database table and i get this error
Parse error: syntax error, unexpected T_VARIABLE in index_altrow.php on line 52

line 52 is:
$table .= "<tr><td class="$class">$arr_value</td></tr>";

here is the code i am using to make the rows alter in color

<?
echo<<<EOF
<!DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

<html>
<head>
<title>Title Here</title>
<style type="text/css">
td.RowOne {
background-color: #bfd9ff;
border: 1px solid #000000;
}
td.RowTwo {
background-color: #e8e8e8;
border: 1px solid #000000;
}
</style>
EOF;

//Build the array
$array = array("value1", "value2", "value3", "value4", "value5");

//Set the Rows
$class1 = "RowOne";
$class2 = "RowTwo";
$class = $class1;

//Start the table
$table = "<users>";

//Loop through the array
foreach($array as $arr_value){
$table .= "<tr><td class="$class">$arr_value</td></tr>";
if($class == $class1){
$class = $class2;
} else {
$class = $class1;
}
}
$table .= "</users>";

//echo the table
echo $table;
?>

"users" is my table name

any help wud be gud :)

IndiaMaster

7:10 am on Jul 14, 2007 (gmt 0)

10+ Year Member



Hi,

I think you need to write
$table .= "<tr><td class=$class>$arr_value</td></tr>";
instead of
$table .= "<tr><td class="$class">$arr_value</td></tr>";

Hope it will work.

dreamcatcher

11:09 am on Jul 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you can use single quotes:

$table .= '<tr><td class="'.$class.'">$arr_value</td></tr>';

or you can escape the quotes:

$table .= "<tr><td class=\"$class\">$arr_value</td></tr>";

dc