Current location: Hot Scripts Forums » General Community » Script Requests » .csv files to php


.csv files to php

Reply
  #1 (permalink)  
Old 01-19-07, 10:20 AM
TGyll TGyll is offline
New Member
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question .csv files to php

Thank you for the help in advance.

I have numerous .csv files from a statistics export program that I would like displayed in tables on my php site. An example of what I would like on my site is here . There are many .csv files that all link together.

What I am trying to do is create a statistics page much like you would see on espn.com where you can see team stats, then click on teams for individual stats etc. These stats would be updated nightly preferably automatically which the program permits. If you click around on the link you will see what I mean. I am very new at php, barely getting this site up and running. Any help would be VERY appreciated.

Last edited by TGyll; 01-19-07 at 10:30 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-19-07, 06:43 PM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
This is a fairly simple thing to do.

Given a file called stats.csv

Code:
Los Angeles,18,14,1,3,31,.861,61,41,14,94,14.9,2,10,101,90.1,3
Buffalo,17,14,2,1,29,.853,59,30,16,62,25.8,1,6,61,90.2,3
NY Rangers,22,14,8,0,28,.636,66,64,18,126,14.3,2,10,130,92.3,2
Anaheim,18,13,3,2,28,.778,75,62,18,74,24.3,0,15,59,74.6,1
Montreal,19,12,4,3,27,.711,66,49,14,65,21.5,3,10,67,85.1,3
You can display your table using this php code:

PHP Code:



<?php
$myFile 
'stats.csv';

$myFileArray file($myFile);

print 
'<table>';

foreach(
$myFileArray as $statsLine)
{
  
$teamStats explode(',',$statsLine);
  print 
'<tr>';
  foreach(
$teamStats as $stats)
  {
    print 
'<td>'.$stats.'</td>'."\n";
  }
  print 
'</tr>';
}
print 
'</table>';
?>
You can put in a counter or use a for loop instead of the inner foreach and give that cell a class name and use a stylesheet to change its color like the one in your sample. I've tested this code and it works.

This code would probably be called in another loop that fed a list of files to it to be converted effectively handling your many files strung together thing.

If you are interested I'd be happy to finish it out for you. Just send me a Private Message on this forum.
__________________
"Things are difficult only while you don't understand them."

Last edited by grafman; 01-19-07 at 06:46 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-19-07, 07:29 PM
TGyll TGyll is offline
New Member
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for the help. I have sent you a PM for a little more help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-20-07, 01:41 PM
TGyll TGyll is offline
New Member
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Still looking for some help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 01-20-07, 02:11 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
What exactly do you need help doing? Since your files/data and web site is unique, this would require custom programming. The code to do this would need to know the file naming scheme, the format of the data within each file, and where, when, and what format to output the data on a page.

This problem is basically, open, read, and parse the proper file at the proper point on the web page and output the contents in the format you want. Since you have not supplied any specific detail, you are not going to get a specific response, only more questions.

The example that grafman posted gives typical code that would read a specific file with csv data and output this in a HTML table. He has provided an answer for your request for a script, as specific as could be done given the information provided.

Edit: LOL - In the same way that you gave -
Quote:
An example of what I would like on my site is here .
- the code that grafman posted is like the code you would need to accomplish this. Being able to turn a desire to have something like something else into reality, is where the art of programming comes in. In short, either you as a programmer or a programmer you hire will be needed to do this.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???

Last edited by mab; 01-20-07 at 02:40 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 01-20-07, 03:03 PM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
You have a PM detailing how to get more assistance. I sent it yesterday.
__________________
"Things are difficult only while you don't understand them."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 01-22-07, 04:39 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
why aren't you using the function fgetcsv for this? it's specially designed for csv.

UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 01-25-07, 04:22 AM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
TyGLL,

Perhaps the pm system isn't working. I've seen several posts where someone didn't receive their messages. I've had one other that didn't get mine. Try again please. I don't like to post emails to the public forum. I don't want the "bots" to get to it and any other nefarious types!

UnrealEd:

I didn't use fgetcsv because "to me" its simpler to construct the html for that table right out of the array produced by file. I do that mainly because many times I have clients find that csv format conflicts with text files that have strings with commas in them. I don't have to change code other than my separator to use another delimiter. Just habits. fgetcsv would work as well!
__________________
"Things are difficult only while you don't understand them."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP multi-dimensional array sorting issue aqw PHP 2 06-25-05 12:09 AM
How to Make my Php output write static Html files cebuy PHP 1 02-04-05 06:52 AM
move files around an ftp server, with php file upload script? wapchimp PHP 2 12-19-04 08:27 AM
PHP Runner , Preview PHP files ! moslehi@gmail.com General Advertisements 3 12-08-04 04:01 PM
php files in a cgi-bin directory epic1231 PHP 7 12-31-03 04:42 PM


All times are GMT -5. The time now is 06:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.