CSS aanpassen aan if/else

Gestart doorJob4 reacties237 weergaven

5 berichten · pagina 1 van 1

Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi allemaal!
Ik ben bezig met een klein financiën systeem, waar er een hele lijst is met verschillende transacties die gedaan zijn. Deze kunnen + of - zijn (inkomend en uitgaand). Nu wil ik graag de + bedragen in groene letters laten zien, en de - bedragen in rode letters. Hieronder mijn code. Kan iemand mij helpen? Ik zoek me suf maar heb tot dusver niks kunnen vinden.

$result = mysql_query("SELECT * FROM kas ORDER BY transactie_datum DESC ") 
or die(mysql_error()); 
while($row = mysql_fetch_array( $result )) { ?>
<table>
    <tr>
        <td width="300"><b>Bedrag</b></td>
        <td width="300"><b>Wat?</b></td>
        <td width="300"><b>Waar/waarvoor?</b></td>
        <td width="300"><b>Transactiedatum</b></td>
        <td width="300"><b>Deze transactie is gedaan door...</b></td>
    </tr>
    <tr>
        <td width="300">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_bedrag[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
        <td width="300">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_cat[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
        <td width="300">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_omsch[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
        <td width="300">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_datum[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
        <td width="300">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruiker[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
    </tr><hr>
</table>[COLOR= #0000BB]<?php[/COLOR]
        
[COLOR= #007700]} 
 
}[/COLOR]
?>
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Codeblok (voorbeeld.php):

1
2
3
4
5
6


if($row[transactie_bedrag] < 0) {
echo

.$row[transactie_bedrag].

;
}
else {
echo

.$row[transactie_bedrag].

;
}
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zou voor zoiets gaan, een stuk korter

<td style="width: 300px; color: [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_bedrag[/COLOR][COLOR= #007700]] <[/COLOR] [COLOR= #0000BB]0[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #DD0000]red[/COLOR] [COLOR= #007700]:[/COLOR] [COLOR= #DD0000]green[/COLOR][COLOR= #007700];[/COLOR] ?>">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_bedrag[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
0
Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
Ik zou voor zoiets gaan, een stuk korter

<td style="width: 300px; color: [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_bedrag[/COLOR][COLOR= #007700]] <[/COLOR] [COLOR= #0000BB]0[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #DD0000]red[/COLOR] [COLOR= #007700]:[/COLOR] [COLOR= #DD0000]green[/COLOR][COLOR= #007700];[/COLOR] ?>">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_bedrag[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
De oplossing van Luukvdo heeft geholpen, die van Stef kwam ik niet helemaal uit. Toch bedankt voor jullie snelle reacties!
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Beter geef je de stijl aan in je stijlblad met een class. Veel netter:

<td class="positive">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_bedrag[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
<td class="negative">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]transactie_bedrag[/COLOR][COLOR= #007700]];[/COLOR] ?></td>


.positive {
color:green;
}

.negative{
color:red;
}
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren