CSV-Import - leichte Abänderungen

Wie verwendet man Module oder Aktion und passt diese an.

CSV-Import - leichte Abänderungen

Beitragvon bastians » 23. Jul 2008, 14:57

Hallo,

ich verwende das Modul "CSV-Datei / Ausgabe als Tabelle" (http://www.redaxo.de/165-Moduldetails.html?module_id=185) von Pixelworks und möchte es ein wenig abändern, auch weil es bisher nur für Version 3.x zur Verfügung steht, aber läuft auch unter 4.x.

Folgendes:
Ich füge eine Tabelle ein und möchte diese nun gestalten und zwar so, dass die Zeilen immer abwechselnd einen anderen Hintergrund haben. Dafür müsste ich CSS-Klassen vergeben aber mit der bisherigen Version ist dies nicht möglich.
Was müsste ich hier am Code verändern?

Code: Alles auswählen
<?
//Define what you want the seperator to be, this could be new line, (\n) a tab (\t) or any other char, for obvious reasons avoid using chars that will be present in the string.  Id suggest a comma, or semicolon.
$sep = ",";

//define file to read
$file = "REX_FILE[1]";
$uri = $REX['HTDOCS_PATH'];
$folder ="files/";

//read the file into an array
$lines = file($uri.$folder.$file);

//count the array
$numlines = count($lines);

//explode the first (0) line which will be the header line
$headers = explode($sep, $lines[0]);

//count the number of headers
$numheaders = count($headers);

$i = 0;

//start formatting output
echo "<table border = 1 cellpadding = 2><tr>";

//loop through the headers outputting them into their own <TD> cells
while($i<$numheaders){
       $headers = str_replace("\"", "", $headers);
       echo "<td>".$headers[$i]."</td>";
       $i++;
       }

echo "</tr>";

$y = 1;

//Output the data, looping through the number of lines of data and also looping through the number of cells in each line, as this is a dynamic number the header length has to be reread.
while($y<$numlines){
       $x=0;
       echo "<TR>";
               while($x<$numheaders){
               $fields = explode($sep, $lines[$y]);
               $fields = str_replace("\"", "", $fields);
               echo "<TD>&nbsp;".$fields[$x]." </TD>";
               $x++;
                       }
       $y++;
       echo "</TR>";
       }

//close the table.
echo "</table>";
?>


Für jede Hilfe bin ich dankbar.
Benutzeravatar
bastians
 
Beiträge: 106
Registriert: 9. Mai 2008, 16:45
Wohnort: Stuttgart

Beitragvon cwenet » 23. Jul 2008, 15:26

Hallo,

ich nehme für den Farbwechsel immer folgendes:

Code: Alles auswählen
printf('<tr bgcolor="%s">', ($zaehler % 2 == 0)? "#ededed" : "white");


$zaehler müsste dann $x bei dir sein, oder so.

Vielleicht kannst du es ja irgendwie einbauen.

Gruss
Christoph
cwenet
 
Beiträge: 355
Registriert: 16. Feb 2006, 09:13
Wohnort: Lake Of Constance

Beitragvon bastians » 23. Jul 2008, 16:12

Danke für den Hinweis, aber funktioniert leider nicht.
Benutzeravatar
bastians
 
Beiträge: 106
Registriert: 9. Mai 2008, 16:45
Wohnort: Stuttgart

Beitragvon zehbaeh » 24. Jul 2008, 18:04

Ich habe das Modul überarbeitet,
siehe: http://www.redaxo.de/165-Moduldetails.h ... ule_id=395
zehbaeh
 
Beiträge: 563
Registriert: 17. Okt 2006, 10:52
Wohnort: Solingen

Beitragvon bastians » 24. Jul 2008, 18:08

Wow, super! :)
dickes Lob!
Benutzeravatar
bastians
 
Beiträge: 106
Registriert: 9. Mai 2008, 16:45
Wohnort: Stuttgart


Zurück zu Module/Aktionen [R4]

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste