Antworten auf deine Fragen:
Neues Thema erstellen

Antworten zum Thema „Tabellen hintergrund prob“

S

s0xtech

Guest

hey

ich hab folgendes prob. Ich hab eine datenbank abfrage. das gibt der in ner tabelle aus. Alle 20 einträge (hab ich begrenzt). Ich will das die zeile immer unterschiedliche hintergrundfarben haben sollen

schwarz
grau
schwarz
grau
schwarz
grau
schwarz
grau

nach dem muster. Wie stelle ich das an ?? for geht nicht oder ??
 

saila

Moderatorle

AW: Tabellen hintergrund prob

Vor

while(....)

setzt du eine neue Var Bsp.:

$xy = 4;

Innerhalb der

while(...) {
//und vor
echo "<tr class=\"$style\">.....";
// machst du eine
if($xy%2) {
$style = "background: blabla";
else {
$style = "background: blublu";
}
}

Das ganze sieht dann in etwa so aus:
PHP:
<?php
$var = 2;
while(.....) {
    if($var%2) {
        $style = "style=\"background: red\"";
    } else {
        $style = "style=\"background: blue\"";
    }
    echo "<tr $style>
            <td>...</td>
         </tr>";
}
?>

Übrigens - Google oder sonstige Suchmaschinen hätten es auch getan ;)
 
S

s0xtech

Guest

AW: Tabellen hintergrund prob

ja danke..
ich wusste ja nicht wonach ich suchen sollte :)

aber... du hast gutes getan. Gott wird dich nicht bestrafen :D

lol danke

##EDIT##
das funzt nicht.
es wird immer das else ausgegeben

ich hab was anderes gefunden
eigentlich nichts weiter als dies:
<?php
$SSAdv_colors1 = array("#CCCCCC","#0033CC");
$SSAdv_k1 = 0;
$SSAdv_m1 = 0;
$SSAdv_change_every1 = 1;
?>
und dies:
<tr bgcolor="<?php
if($SSAdv_m1%$SSAdv_change_every1==0 && $SSAdv_m1>0){
$SSAdv_k1++;
}
print $SSAdv_colors1[$SSAdv_k1%count($SSAdv_colors1)];
$SSAdv_m1++;
?>">
[/puote]
 
Zuletzt bearbeitet von einem Moderator:

Duddle

Posting-Frequenz: 14µHz

AW: Tabellen hintergrund prob

Du musst natürlich die Entscheidungsvariable bei jedem Durchgang ändern, sonst entscheidet er sich immer gleich.

PHP:
<?php
$var = 2;
while(.....) {
    if($var%2) {
        $style = "style=\"background: red\"";
    } else {
        $style = "style=\"background: blue\"";
    }
    $var++;
    echo "<tr $style>
            <td>...</td>
         </tr>";
}
?>


Duddle
 

blackout

Schaf im Wolfspelz

AW: Tabellen hintergrund prob

Ich hab dazu mal eine Klasse geschrieben, vielleicht wird sie endlich mal gebraucht ;)

PHP:
// Verwendungsbeispiel
$states = array('A', 'B', 'C');
$osz = new oszillation($states);
for($i = 10; $i; $i--) {
	echo $osz->oszillate()." $i \n";
}


/*
	Creates an object that helps doing oszillating things, such as table rows with alternating colours.
	Bugs/known issues: if the absolute value of parameter $by of oszillate() is greater than number_of_states the function won't work (producing notices over and over)
*/
class oszillation {
	var $states;
	var $currentstate; // The pointer
	var $number_of_states;
	
	/*
		void __construct(array $values)
		array $values: Values contain the different strings that should take turns. The array will be reindexed.
	*/
	function __construct($values) {
		$this->currentstate = 0;
		$this->states = array();
		foreach($values as $single_state) { // Reindex
			$this->states[] = $single_state;
		}
		$this->number_of_states = count($this->states);
		echo "States: ".$this->number_of_states." \n\n";
	}
	function oszillation($values){$this->__construct($values);} // PHP4
	
	
	/*
		mixed oszillate([int $by])
		signed int $by (Default 1): Determines how far the internal pointer is pushed forward after (!) the oszillation
		
		Returns the current state of the oszillation and sets the internal pointer to a new location (which is then the current state given back upon next use of the function).
		Returns the value the pointer points to.
	*/
	function oszillate($by = 1) {
		$return = $this->states[$this->currentstate];
		$this->currentstate += (int)$by;
		if($this->currentstate > $this->number_of_states - 1 OR $this->currentstate < 0) { // Range exceeded
			$this->currentstate = $this->currentstate - floor($this->currentstate / $this->number_of_states) * $this->number_of_states; // Mathematical modulo
		}
		return $return;
	}
}
 
Zuletzt bearbeitet:
Bilder bitte hier hochladen und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Antworten auf deine Fragen:
Neues Thema erstellen

Willkommen auf PSD-Tutorials.de

In unseren Foren vernetzt du dich mit anderen Personen, um dich rund um die Themen Fotografie, Grafik, Gestaltung, Bildbearbeitung und 3D auszutauschen. Außerdem schalten wir für dich regelmäßig kostenlose Inhalte frei. Liebe Grüße senden dir die PSD-Gründer Stefan und Matthias Petri aus Waren an der Müritz. Hier erfährst du mehr über uns.

Stefan und Matthias Petri von PSD-Tutorials.de

Nächster neuer Gratisinhalt

03
Stunden
:
:
25
Minuten
:
:
19
Sekunden

Neueste Themen & Antworten

Flatrate für Tutorials, Assets, Vorlagen

Statistik des Forums

Themen
175.189
Beiträge
2.582.077
Mitglieder
67.259
Neuestes Mitglied
SaschMasch1312
Oben