/    Sign up×
Community /Pin to ProfileBookmark

css for csv file via php

ok, so i have a csv file that i’m calling with a php script:

[CODE]<?php
$file=”youths.csv”;
if(file_exists($file) && is_readable($file)){
if($fp=fopen($file,’r’)) {
if($line=fgetcsv($fp)) {
print “<table>n”;
do {
print “<tr>”;
foreach($line as $cell){
print “<td>$cell</td>”;
}
print “</tr>n”;
}while($line=fgetcsv($fp));
print “</table>n”;
}
}else{
print “Failed to open file”;
}
}else{
print file_exists($file)?
“File $file is not readable”:
“File $file does not exist”;
}
?>[/CODE]

i would like to know how to apply css styles to this table. i would like to change the width of each column, and change the font style and color of the column labels. i’m not too experienced with php but i do know some basic css.

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 22.2008 — The PHP behind the HTML doesn't matter and doesn't help us at this point. Post the resulting HTML or better, a link.
Copy linkTweet thisAlerts:
@CharlesDec 22.2008 — I've taken the liberty of cleaning up your XHTML a bit; it was far from valid. Note, however, that with tables you aren't setting the width, you are setting the min-width. Cells will always expand to accomodate.&lt;!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Stop Tobacco Addiction Program | Bad Boys (and Girls!)&lt;/title&gt;

&lt;style type="text/css"&gt;
body {background-color:#000; color:#fff}
table {margin:auto}
th, td {
padding:1ex;
width:5em;
}
th {
color:#aaa;
font-style:italic;
text-transform:lowercase;
vertical-align:bottom;
}
&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;p class="plea"&gt;&lt;a href="/smoking/youths.php?doLogout=true"&gt;Please click here to log out when you are finished!&lt;/a&gt;&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th scope="col"&gt;LAST NAME&lt;/th&gt;&lt;th scope="col"&gt;FIRST NAME&lt;/th&gt;&lt;th scope="col"&gt;SCHOOL&lt;/th&gt;&lt;th scope="col"&gt;DEPT&lt;/th&gt;&lt;th scope="col"&gt;PHONE #&lt;/th&gt;&lt;th scope="col"&gt;DOB&lt;/th&gt;&lt;th scope="col"&gt;CLASS 1&lt;/th&gt;&lt;th scope="col"&gt;CLASS 2&lt;/th&gt;&lt;th scope="col"&gt;CLASS 3&lt;/th&gt;&lt;th scope="col"&gt;CLASS 4&lt;/th&gt;&lt;th&gt;NOTES&lt;/th scope="col"&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;JOHNSON&lt;/td&gt;&lt;td&gt;BOBBY&lt;/td&gt;&lt;td&gt;MY H.S.&lt;/td&gt;&lt;td&gt;TFCS&lt;/td&gt;&lt;td&gt;555-5555&lt;/td&gt;&lt;td&gt;1/1/2000&lt;/td&gt;&lt;td&gt;YES&lt;/td&gt;&lt;td&gt;YES&lt;/td&gt;&lt;td&gt;YES&lt;/td&gt;&lt;td&gt;YES&lt;/td&gt;&lt;td&gt;PASSED SUCCESSFULLY&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt;&lt;td&gt;SMITH &lt;/td&gt;&lt;td&gt;SALLY&lt;/td&gt;&lt;td&gt;MY M.S.&lt;/td&gt;&lt;td&gt;TFPD&lt;/td&gt;&lt;td&gt;555-5555&lt;/td&gt;&lt;td&gt;10/10/2020&lt;/td&gt;&lt;td&gt;YES&lt;/td&gt;&lt;td&gt;NO&lt;/td&gt;&lt;td&gt;YES&lt;/td&gt;&lt;td&gt;YES&lt;/td&gt;&lt;td&gt;MISSED 1 CLASS&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/body&gt;

&lt;/html&gt;
Copy linkTweet thisAlerts:
@King_EvilauthorDec 22.2008 — thanks charles. although i think i a made a couple changes after you checked the html. now, the log out line and my footer are aligned to the left (instead of center) and the table font got really really small. also, i can't change the table html because that's being generated by the php.
Copy linkTweet thisAlerts:
@King_EvilauthorDec 22.2008 — oh, i figured out tho change the font size. duh.
×

Success!

Help @King_Evil spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...