Jump to content

Outputing a CSV file to HTML table? Beginner


randallpink83

Recommended Posts

Just so you are warned, I'm a complete newbie. I have been trying to go through tutorials to learn what I need to do, but I'm an idiot and not grasping it. Unfortunately I need to get this done ASAP. Would greatly appreciate any help.

 

I got a .csv file that has about 500+ players info on it... It's only 3 columns; the players rank, their name, and the amount of points they have.

 

So what I want to accomplish is first to be able to read the file obviously, fopen - fgetcsv, whatever it takes. then pull the 3 fields out to where i can define them, so they will be posted with correct html opening and closing table tags... And for the really complicated part (or so I think), I want the first line printed to have an included CSS style in the <tr> so it will make the text bigger (cause that player will be number one obviously lol). and I want to do the same for like 2 through 10.. and so forth.

 

I know this is asking a lot. I don't expect you to write it out for me, but if you could point me in the right direction that would be great, I'm so lost.

 

If I had this completed then I could just update the csv file every week without having to mess with the html anymore!! Thank you.

Thanks for posting that. But I spent 3hrs straight trying to get it to work with no success... I just get a bunch of errors that I don't know how to fix, or worse, I just get a blank page.

 

This is so insanely frustrating.

 

lets try this

<?php

$arrResult = array();
$handle = fopen("playerpoints.csv", "r");
if( $handle ) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$arrResult[] = $data;
}
fclose($handle);
}
?>

 

What would be the next code I got to add just so I can freakin see the results on the website? at least that would be a step forward, something tangible. I've tried countless coding but nothing works. Except for php.net/fgetcvs example... but I don't know how to get rid of the fact that its counting up intervals making any table attempt grow larger and larger. haha.

Sorry but I been at this for nearly two days now, I'm so tired. But really hope someone can help out a bit. thanks...

 

here is a code I got working properly

 

<?php


$filename = "playerpoints.csv";

function viewlog($filename) {
$fp = fopen($filename,"r");
$file = fread($fp,65535);
$replaced = eregi_replace(",", "<td>", $file);
$replaced2 = eregi_replace("\n", "<tr><td>", $replaced);
$replaced3 = eregi_replace("\r", "<tr><td>", $replaced2);
fclose($fp);

return $replaced3;
}
echo "<table width='384' height='2149' border='1'>";

echo "<tr>";
echo "<th width='61' align='center'>Rank</th>";
echo "<th width='224' align='center'>Name</th>";
echo "<th width='74' align='center'>Points</th>";
echo "</tr>";
echo "<tr>";
echo "<td>";

echo viewlog($filename);
echo "</td>";
echo "</tr>";
echo "</table>";
?>

 

 

But I've read somewhere that eregi_replace will be taken out of use very soon... Also this code does not output proper open and closing html tags... except for the beginning and ending ones that I placed with echo.

 

And I would still like to define different properties  for the first few html rows and columns generated. Any ideas?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.