Reply to Re: Parsing CSV-file and adding CSS to style

Your name:

Reply:


Posted by Ψrjan Langbakk on 06/24/06 13:42

Den 24.06.2006 14:54, skriblet Rik fΓΈlgende:
> Why use ""? '' is much simpler here:
> $this->html .= '
> <table id="dusjkabinetter">
> <thead>
> <tr>
> <th id="th2" valign="top" align="left">Prod. nr:</th>
> <th id="th3" valign="top" align="left">Bilder:<br />(klikk
> for stΓΈrre visning):</th>
> <th id="th4" valign="top" align="left">Beskrivelse:</th>
> <th id="th5" valign="top" align="left">Pris:</th>
> </tr>
> </thead>";
>
>> while(($row = fgetcsv($csvHandle, filesize($csvFile))) !== false){
>> $this->html .= "<tr>";
>> foreach($row as $field){
>> $this->html .= "<td>$field</td>";
>> }
>> $this->html .= "</tr>\n";
>> }
>
> Seeing as you know the number of array-elements here, replace with:
> $rowhtml ='
> <tr>
> <td>%s</td>
> <td>%s</td>
> <td>%s</td>
> <td align="right">%s</td>
> </tr>';
> while(($row = fgetcsv($csvHandle, filesize($csvFile))) !== false){
> $this->html = vsprintf($rowhtml, $row);
> }

I tried doing as you said above, but I ended up with no <thead>, and
only one of the <tr>s shows up - the last one (only two in the CSV-file
at the moment, but still).

And, also, the whole thing is centered.

Maybe I didn't do it right?

Here's the code after replacment:

<?php
class csv{
/* This class builds a html table from the contents of a CSV file. */

var $html = '';

function csv($csvFile){
if(!$csvHandle = fopen($csvFile, 'r')){
$this->html .= "Couldn't open $csvFile.";
}
else{
$this->html .= '
<table id="dusjkabinetter">
<thead>
<tr>
<th id="th2" valign="top" align="left">Prod. nr:</th>
<th id="th3" valign="top" align="left">Bilder:<br />(klikk
for stΓΈrre visning):</th>
<th id="th4" valign="top" align="left">Beskrivelse:</th>
<th id="th5" valign="top" align="left">Pris:</th>
</tr>
</thead>'; <-- I changed this from " to ' - else it wouldn't
parse at all.
$rowhtml ='
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td align="right">%s</td>
</tr>';
while(($row = fgetcsv($csvHandle, filesize($csvFile))) !== false){
$this->html = vsprintf($rowhtml, $row);
}
fclose($csvHandle);
$this->html .= "</table>\n\n\n";
}
}

function getHtml(){
return $this->html;
}
}

echo <<<TABELL_START
TABELL_START;

$html .= "<h2>Dusjkabinetter</h2>\n";
$mycsv = new csv('csv-filer/dusjkabinetter.csv', ' ');
$html .= $mycsv->getHtml();

echo $html;

echo <<<TABELL_SLUTT
TABELL_SLUTT;

?>
--
mvh
Ørjan Langbakk

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация