hi everyone,
i write data from database to the csv file,but i face problem how to print the csv file with multiple colors background for example first line is green then second line must be blue,
please help me how can i do this in php

You shouldn't post the same question in multiple forums. Start somewhere and if you don't get an answer there, you will probably get a suggestion on the best place to get an answer.

A CSV file is pretty simple. It is almost the same as a text file in terms of any sort of formatting. If you want to save the file with formatting included, then you should save it in some other format

You don't say how you want to print this file. If you are creating the file in PHP then saving it locally on your PC, then you could open it in Excel or some other spreadsheet program and manually add colors then print it. If it is still on the server, you could open it in a PHP program and have the program add colors to the text. You can't save formatting in a CSV file as you would in a Word (.doc) file.

commented: If I'd seen this I wouldn't have posted. +13

Represent the csv file in a table, so you can add styling to the the rows and or columns.

If you display contents in a table define two CSS classes for row background color - one for even rows and one for odd rows.

.tr_even {background_color: gray;}
.tr_odd {background_color: white;}

Then check the row number and use code:

($row_No % 2) ? echo '<tr class="tr_odd">' : echo '<tr class="tr_even">

Thank you for helping,
Actually i get data from database and then write the data to csv file,the generated csv file still on the server with download link,i want if the user download the file,it must be multiple colors,
how can i do it

I am afraid you can't. CSV is as far as I know a text file and can not contain formatting. You should save your data in excel or ods or pdf (or similar) to use formatting.

Thank you
Then how can i generate that excel file,please any advise

For info on saving to Excel click here.

I suggest you consider using PDF instead. Click here for info on how you could do that.