Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4062862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:39:08+00:00 2026-05-20T15:39:08+00:00

First off, I would like to say that I am just starting with PHP

  • 0

First off, I would like to say that I am just starting with PHP so please be kind. What I am trying to do is print a table from a csv file. The first row I want to be bold with a gray background color. The next rows should alternate with white and green backgrounds with text that is not bold. Below is my attempt, but it just produces a table with all bold text that has a gray background

<?php
echo "<html><body><table>\n\n";
$f = fopen("acsv.csv", "r");

$green = "#DDFFCC";
$white = "#FFFFFF";
$grey = "#EEEEEE";
$color = "#EEEEEE";
echo "<table border=1 cellpadding=4 cellspacing=0>";
echo "<tr>";



while (($line = fgetcsv($f)) !== false) {


        foreach ($line as $cell) {
                if ($color = "#EEEEEE"){
                    echo "<td bgcolor= ".$color."><b>" . htmlspecialchars($cell) . "</b></td>";
                }
                else{
                    echo "<td bgcolor= ".$color.">" . htmlspecialchars($cell) . "</td>";
                }

        }
        echo "<tr>\n";

        switch($color){
            case "#EEEEEE":
                $color = "#FFFFFF";
                break;
            case "#FFFFFF":
                $color = "#DDFFCC";
                break;
            case "#DDFFCC":
                $color = "#FFFFFF";
                break;
        }
}
fclose($f);
echo "\n</table></body></html>";

EDIT:

I would also like to know how to define the colors with meaningful names to make the code more readable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:39:09+00:00Added an answer on May 20, 2026 at 3:39 pm

    To check whether $color is set to “#EEEEEE”, you need to use a double equals (==) in your if statement, similar to C/C++/C#. Otherwise, you’re just telling PHP to set $color to “#EEEEEE”.

    if ($color == "#EEEEEE"){ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off I would like to say that I think that my question may
First off I would like to say that this is my first post and
First off, I would like to say that I am very new to SharePoint
First off I would like to say that I have done ample research on
First off, I would like to make clear, that I am SUPER NEW TO
Just first off I'll say that the context here is Actionscript 3.0 (IDE: Flashbuilder)
First off, I think I'm trying to use Spring incorrectly, but confirmation would be
First off let me just say, i dont want anyone to post solutions because
Hi first off I'd like to say I am new to the site and
First off, let me say that this is not homework (I am an A-Level

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.