XHTMLforum

XHTMLforum (http://xhtmlforum.de/index.php)
-   CSS (http://xhtmlforum.de/forumdisplay.php?f=73)
-   -   Bestimmte Websiteinhalte farblich markieren (http://xhtmlforum.de/showthread.php?t=74218)

asncm 21.04.2021 15:54

Bestimmte Websiteinhalte farblich markieren
 
Hallo zusammen.

Ich habe eine index.php die eine CSV Datei wiederspiegelt.

Code:

<?php
// CSV-Datei in eine HTML-Tabelle auslesen

$daten = file("http://www.beispielseitentext.de/meinedatei.csv", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

echo '<table border>';

foreach ($daten as $nr => $data) {
 list($spalte1, $spalte2, $spalte3, $spalte4, $spalte5, $spalte6, $spalte7, $spalte8, $spalte9, $spalte10, $spalte11, $spalte12, $spalte13, $spalte14, $spalte15, $spalte16, $spalte17) = explode(";", $data); // ; Trennzeichen
 if ($nr == 0) {
  echo '<tr><th>' . $spalte1 . '</th><th>' . $spalte2 . '</th><th>' . $spalte3 . '</th><th>' . $spalte4 . '</th><th>' . $spalte5 . '</th><th>' . $spalte6 . '</th><th>' . $spalte7 . '</th><th>' . $spalte8 . '</th><th>' . $spalte9 . '</th><th>' . $spalte10 . '</th><th>' . $spalte11 . '</th><th>' . $spalte12 . '</th><th>' . $spalte13 . '</th><th>' . $spalte14 . '</th><th>' . $spalte15 . '</th><th>' . $spalte16 . '</th><th>' . $spalte17 . '</th>';
 }
 else {
  echo '<tr><td>' . $spalte1 . '</td><td>' . $spalte2 . '</td><td>' . $spalte3 . '</td><td>' . $spalte4 . '</td><td>' . $spalte5 . '</td><td>' . $spalte6 . '</td><td>' . $spalte7 . '</td><td>' . $spalte8 . '</td><td>' . $spalte9 . '</td><td>' . $spalte10 . '</td><td>' . $spalte11 . '</td><td>' . $spalte12 . '</td><td>' . $spalte13 . '</td><td>' . $spalte14 . '</td><td>' . $spalte15 . '</td><td>' . $spalte16 . '</td><td>' . $spalte17 . '</td>';
 }
}

echo '</table>';
?>

Nun... Ich habe in Spalte 6 bestimmte Zahlen.
Beispiel 179 und würde dann per CSS die ganze Zeile Fablich in Rot markieren lassen.

Danke für eure Hilfe, wenn es klappt.

cloned 22.04.2021 08:47

Gib den gewünschten Datensätzen eine eigene Klasse und style die dann mittels CSS.

asncm 22.04.2021 18:09

So.
konnte das hier umsetzen:
Code:

<?php
$spalte6 = str_replace('101', '<font style="color: #FE2E2E;">101</font>', $spalte6);
$spalte5 = str_replace('101', '<font style="color: #FFF;background-color:#FE2E2E;font-weight:bold;">TEST</font>', $spalte6);

Wie kann ich hier jetzt mehrere Varianten ansteuern ?
Beispiel:
Variante 1 Suche nach 101 funktioniert Ergebnis = TEST
Variante 2 Suche nach 101 = TEST und weitere Suche 332 = TEST2
Da sollen noch mehr varianten rein.

http://firmenmanagementcloud.de/Unbenannt.PNG

Habe versucht die Suche untereinander nochmal rein zu kopieren...
Klappt aber nicht.
Code:

$spalte6 = str_replace('101', '<font style="color: #FE2E2E;">101</font>', $spalte6);
$spalte5 = str_replace('101', '<font style="color: #FFF;background-color:#FE2E2E;font-weight:bold;">TEST</font>', $spalte6);
$spalte6 = str_replace('332', '<font style="color: #FE2E2E;">332</font>', $spalte6);
$spalte5 = str_replace('332', '<font style="color: #FFF;background-color:#FE2E2E;font-weight:bold;">TEST2</font>', $spalte6);

Vielleicht eine Idee ?

Danke

cloned 23.04.2021 08:13

Verwende niemals <font> Tags. Außer du bist im Jahre 1990 stecken geblieben.
Wie gesagt, zuerst musst du eine Klasse vergeben:

Code:

$class = $spalte1 == 100 ? 'class="highlight"' : '';
echo '<tr><td '. $class .'>' ....

Dann steht hier entweder <tr><td class="highlight"> oder eben nur <tr><td>, je nachdem ob spalte1 100 ist oder nicht (das bitte auf die von dir gewünschten Conditions ändern.

Im CSS schreibst du dann:

Code:

.highlight {
  background-color: green; /* Hier die Styles einfügen die du wirklich brauchst und nicht die HG Farbe auf grün setzen*/
}

Du kannst so natürlich auch mehrere Klassen vergeben für unterschiedliche Styles.

asncm 24.04.2021 19:39

Hallo nochmal.

Irgendwie bekomme ich das ding nicht zum laufen....

Wenn ich deinen Code eingefügt habe lief Garnichts mehr.

Habe das jetzt so gemacht:
CSS:
Code:

<style type="text/css">


table, th, td {
  border-collapse: collapse;
  padding: .3em .5em;
}

table {
 margin-left: 1em;}

th, caption {
  background-color: #FE2E2E;
  color: #fff;
  border: thin solid #666;
}

td {
 background-image: linear-gradient(#f9f9f9, #e3e3e3);
 border-left: thin solid #666;
 border-right: thin solid #666;
}

tfoot {
  border-bottom: thin solid #666;
}

caption {
  font-size: 1.5em;
  border-radius: .5em .5em 0 0;
  padding: .5em 0 0 0
}
.highlight {
  background-color: #FE2E2E;
}
</style>

und so die Datei importiert:
Code:

<?php
// CSV-Datei in eine HTML-Tabelle auslesen

$daten = file("http://www.beispielseitentext.de/meinedatei.csv", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

echo '<table border>';

foreach ($daten as $nr => $data) {
 list($spalte1, $spalte2, $spalte3, $spalte4, $spalte5, $spalte6, $spalte7, $spalte8, $spalte9, $spalte10, $spalte11, $spalte12, $spalte13, $spalte14, $spalte15, $spalte16, $spalte17) = explode(";", $data); // ; Trennzeichen
 if ($nr == 0) {
  echo '<tr><th>' . $spalte1 . '</th><th>' . $spalte2 . '</th><th>' . $spalte3 . '</th><th>' . $spalte4 . '</th><th>' . $spalte5 . '</th><th>' . $spalte6 . '</th><th>' . $spalte7 . '</th><th>' . $spalte8 . '</th><th>' . $spalte9 . '</th><th>' . $spalte10 . '</th><th>' . $spalte11 . '</th><th>' . $spalte12 . '</th><th>' . $spalte13 . '</th><th>' . $spalte14 . '</th><th>' . $spalte15 . '</th><th>' . $spalte16 . '</th><th>' . $spalte17 . '</th>';
 }
 else {

$class = $spalte6 == 101 ? $class=$spalte5="highlight" : $spalte6;

  echo '<tr><td>' . $spalte1 . '</td><td>' . $spalte2 . '</td><td>' . $spalte3 . '</td><td>' . $spalte4 . '</td><td>' . $spalte5 . '</td><td>' . $spalte6 . '</td><td>' . $spalte7 . '</td><td>' . $spalte8 . '</td><td>' . $spalte9 . '</td><td>' . $spalte10 . '</td><td>' . $spalte11 . '</td><td>' . $spalte12 . '</td><td>' . $spalte13 . '</td><td>' . $spalte14 . '</td><td>' . $spalte15 . '</td><td>' . $spalte16 . '</td><td>' . $spalte17 . '</td>';
 }
}

echo '</table>';
?>

Das Ergebnis hier ist:
http://firmenmanagementcloud.de/Unbenannt3.PNG

So sollte es eigentlich aussehen:
http://firmenmanagementcloud.de/Unbenannt2.PNG


Mit PHP muss ich mich erst einmal anfreunden.
Minimale Sachen konnte ich schon umsetzen.
Leider stehe ich hier bei einem Rätsel.

basti1012 24.04.2021 23:29

Ich würde es so versuchen
http://sebastian1012.bplaced.net/tes...rben/index.php

cloned 26.04.2021 08:41

Zitat:

Zitat von asncm (Beitrag 554740)
Wenn ich deinen Code eingefügt habe lief Garnichts mehr.

Das ist keine Fehlerbeschreibung. Entweder es fliegt ein Fehler im PHP Teil oder die Ausgabe ist zwar da, aber nicht korrekt gerendert. Oder irgendetwas anderes.

Ansonsten kann ich nur wiederholen was ich schon dreimal geschrieben habe:

Du brauchst eine Klasse welche du dann im CSS ansprichst:

Code:

<td class="deine-klasse"> 192389023 </td>

.deine-klasse {background-color: pink}

Da ich kein PHP kann ist es gut möglich dass mein PHP code nicht fehlerfrei ist, aber das Grundprinzip sollte doch verständlich und ersichtlich sein.


Auch frage ich mich warum hier nicht mit einem array gearbeitet wird:
Code:

<?php
// CSV-Datei in eine HTML-Tabelle auslesen

$daten = file("http://www.beispielseitentext.de/meinedatei.csv", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

echo '<table border>';

foreach ($daten as $nr => $data) {
$parts = explode(";", $data);
  echo '<tr>'
  foreach ($parts as $part) {
    echo '<td>' . $part . '</td>';
  }
  echo '</tr>'
}

echo '</table>';
?>



Alle Zeitangaben in WEZ +2. Es ist jetzt 08:48 Uhr.

Powered by vBulletin® Version 3.8.11 (Deutsch)
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

© Dirk H. 2003 - 2023