Using Table HTML tag in PhP

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
zak100
New php-forum User
New php-forum User
Posts: 9
Joined: Fri May 24, 2019 1:36 pm

Sat Sep 21, 2019 11:32 am

Hi,
I wrote the following code:

Code: Select all

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

zULFI
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 845
Joined: Mon Feb 22, 2016 5:52 pm

Sun Sep 22, 2019 11:59 am

Because you have an extra space in this line

Code: Select all

   print ("<TR><TD BGCOLOR=\ "$rowColor\">");
the parser cannot compile the file.

If you are going to escape a character, you need to put if straight after the slash:

Code: Select all

   print ("<TR><TD BGCOLOR=\"$rowColor\">");
You should use css not html to set the background colour, you can also alternate colours.
Post Reply