Forum Moderators: coopster
First off I'm not a programmer. I only work simple web pages in HTML. :D I know very little about PHP and can only seem to master the very beginning basics. Help!
Here's my problem: I have a file called projects.php. Within projects.php there is this line:
<? include("listofprojects.csv");?>
listofprojects.csv is a comma-delimited file that shows all of my client's current projects including fields like ProjectName, Builder, ModelAddress, City, State, Zip, County, & MapLink. (The client keeps this list in an Excel file & I converted it to a CSV file.)
When I use the above include line, of course all the data runs together!
What do I need to do to make it look good? Like in columns, for example? Do I have to parse it? I don't even know what parsing is! Is this a complicated sort of thing I want to do?
Please help and thank you so much,
Morcar
I see the CSV as a two-way vector
A) You may get info from a DB in a CSV file form
B) you can do the reverse for ex: type some input regarding a shopping cart products in XL format then convert in CSV and plug the new info in your cart products list so in one shot you might add many new products
In your case you need to create an HTML page with the CSV info or create a DB feed the DB with the CSV, query that DB then format the output
I told you not fun!
Other members might have better ideas.
function parse_csv($file) {
if(!($op = fopen($file.".csv"))) return false;
$csv = fread [php.net]($op, filesize [php.net]($file.".csv"));
$csv = implode [php.net]("</tr><tr>\n", explode [php.net]("\n", $csv));
$csv = implode("</td><td>\n", explode(",", $csv));
$table = "<table><tr><td>".$csv."</td></tr></table>";
return $table;
}
<? echo parse_csv("listofprojects");?>
Warning: fopen() expects at least 2 parameters, 1 given in /projects.php on line 22
Thank you again. All help is greatly appreciated.
function parse_csv($file) {
if(!($op = fopen($file.".csv", "r"))) return false;
$csv = fread($op, filesize($file.".csv"));
$csv = implode("</tr><tr>\n", explode("\n", $csv));
$csv = implode("</td><td>\n", explode(",", $csv));
$table = "<table><tr><td>".$csv."</td></tr></table>";
return $table;
}
Best regards
Michal Cibor
PS. Morcar wrote he's not a programmer... My fault :)
function parse_csv($file) {
if(!($op = fopen($file.".csv", "r"))) return false;
$csv = rtrim(fread($op, filesize($file.".csv")), "\n");
$csv = implode("</td>\n</tr>\n<tr>\n<td>", explode("\n", $csv));
$csv = implode("</td>\n<td>", explode(",", $csv));$table = "<table border=\"1\"><tr>\n<td>".$csv."</td>\n</tr></table>";
return $table;
}
Sorry Morcar again:)
Best regards
Michal Cibor