Problem with table or color tag

Hi,
I have written the following code on Php. i am using nginx server.
`

<?php
function useColor(){
   static $colorValue;
   if($colorValue == "#00FF00"){
      $colorValue= "#CCFFCC";
   }
   else{
      $colorValue = "#00FF00";
   }
   return ($colorValue);
}

print("<TABLE width=\"300\">\n");
for($count =0; $count <10; $count++) {
   $rowColor = useColor();
   print ("<TR><TD BGCOLOR=\ "$rowColor\">");
   print("Row number $count</TD></TR>\n");
}
   print("</TABLE>\n");
?>

I am not any output when I execute this program on the browser.
My error.log file shows an old dated error related to this file (color_book49.php:

2019/09/15 23:56:33 [error] 1167#1167: *8 FastCGI sent in stderr: “PHP message: PHP Parse error: syntax error, unexpected ‘300’ (T_LNUMBER) in /var/www/html/color_book49.php on line 13” while reading response header from upstream, client: 127.0.0.1, server: _, request: “GET /color_book49.php HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php/php7.2-fpm.sock:”, host: “localhost”

Some body plEASE GUIDE ME HOW TO FIX THIS ERROR.

At first remove function useColor() and replace

$rowColor = useColor();

with

$rowColor = ($count % 2 == 0) ? '#00FF00' : '#CCFFCC';

Hi there Zulfi6000,

you really should not be using the width attribute for the
table element or the bgcolor attribute for the td element. :eek:

These items should now be set with CSS. :winky:

Here is an example php file…

<!DOCTYPE HTML>
<html lang="en">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<title>untitled document</title>

<!--<link rel="stylesheet" href="screen.css" media="screen">-->

<style media="screen">
body {
    background-color: #f9f9f9;
    font: normal 1em / 1.5em BlinkMacSystemFont, -apple-system, 'Segoe UI', roboto, helvetica, arial, sans-serif;
 }
#mytable {
     width: 100%;
     max-width: 18.75em;
     border-collapse: collapse;
 }
#mytable td {
    padding: 0.5em;
    border: 1px solid #999;
 }
#mytable tr:nth-child( odd ) td {
    background-color: #0f0;
 }
#mytable tr:nth-child( even ) td {
    background-color: #cfc;
 }
</style>

</head>
<body> 
 <?php
   $num = 10;
   echo '<table id="mytable">' . "\n" ;
   echo '<tbody>'. "\n";
    for( $count = 0; $count < $num; $count ++ ) {
         echo '<tr>' . "\n";
         echo '<td>' .$count. '</td>' . "\n";
         echo '</tr>' . "\n";
      }
  echo '<tbody>' . "\n";  
  echo '</table>';
 ?>

</body>
</html>

coothead

1 Like

Hi,
Thanks. Actually I am using an old book “Core Php Programming”. I think I have to use some latest e-book.

The error was due to a space after the delimiting left-hand-slash:

// BAD 
// print ("<TR><TD BGCOLOR=\ "$rowColor\">");

// GOOD
// print ("<TR><TD BGCOLOR=\"$rowColor\">");

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.