Cambiare colore ad un td se il campo XXX è = a XXX

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Come da titolo, sarebbe possibile cambiare colore ad un td se il campo XX è con valore= 'XX' ??
Avrei bisogno di mettere in rilievo alcuni record...
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Mi spiego meglio.
In un mio db, cerco delle fatture, e vorrei che gli acconti venissero evidenziati in qualche modo per differenziarli dai pagamenti completi.
Quindi pensavo ad una formula del tipo (Se il campo 'tipi' è = a 'Acconto' allora evidenzia quella riga)
Grazie a chi vorrà aiutarmi.
 

giamma

Utente Attivo
4 Mag 2005
111
0
0
gli metti una condizione se $a=acconto stampa <strong>a</strong> seno a...
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
gli metti una condizione se $a=acconto stampa <strong>a</strong> seno a...
Ciao giamma.
Il mio script è questo:
PHP:
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr>

<th align='center' width=''><font size='2'>Cliente</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Numero</th>
<th align='center' width=''><font size='2'>Emissione doc.</th>
<th align='center' width=''><font size='2'>Codice cliente</th>
<th align='center' width=''><font size='2'>Importo euro</th>
<th align='center' width=''><font size='2'>-</th>
<th align='center' width=''><font size='2'>Data operazione</th>
<th align='center' width=''><font size='2'>Tipo operazione</th>
</tr>"; 
$totale_importo = 0;
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
        
    echo "<tr>
     <td align='center'><font size='2'>".$row['nome']."</font></td>
     <td align='center'><font size='2'>".$row['doc']."</font></td>
     <td align='center'><font size='2'>".$row['numero']."</font></td>
     <td align='center'><font size='2'>".$row['emissione']."</font></td>
     <td align='center'><font size='2'>".$row['codcliente']."</font></td>
     <td align='center'><font size='2'>".$row['importo']."</font></td>
     <td align='center' width='20'><font size='2'></font></td>
     <td align='center'><font size='2'>".$row['data']."</font></td>
     <td align='center'><font size='2'>".$row['tipo']."</font></td></tr>";
              $importo=mysql_result($result,$i,"importo");
    $totale_importo += $importo;
    $i++;  
}  
echo "</table><br>";
In quale punto lo dovrei inserire e come?
 

giamma

Utente Attivo
4 Mag 2005
111
0
0
dentro il while dovresti mettere una condizione e che non capisco quale array determini l'acconto forse dall'importo? io parto dal presupposto che la tua risposta sia si e quindi:
PHP:
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>";  
echo "<tr> 

<th align='center' width=''><font size='2'>Cliente</th> 
<th align='center' width=''><font size='2'>Documento</th> 
<th align='center' width=''><font size='2'>Numero</th> 
<th align='center' width=''><font size='2'>Emissione doc.</th> 
<th align='center' width=''><font size='2'>Codice cliente</th> 
<th align='center' width=''><font size='2'>Importo euro</th> 
<th align='center' width=''><font size='2'>-</th> 
<th align='center' width=''><font size='2'>Data operazione</th> 
<th align='center' width=''><font size='2'>Tipo operazione</th> 
</tr>";  
$totale_importo = 0; 
while($row = mysql_fetch_array( $result )) {  
    $id=$row['id']; 
         
    echo "<tr> 
     <td align='center'><font size='2'>".$row['nome']."</font></td> 
     <td align='center'><font size='2'>".$row['doc']."</font></td> 
     <td align='center'><font size='2'>".$row['numero']."</font></td> 
     <td align='center'><font size='2'>".$row['emissione']."</font></td> 
     <td align='center'><font size='2'>".$row['codcliente']."</font></td> ";
if($row['importo']<=1200){ //quindi qui ti controlla se il valore è uguale maggiore di 1200 ipotesi se i si utilizzerà il marcatore strong 
     echo "<td align='center'><font size='2'><strong>".$row['importo']."</strong></font></td>";
}else{
    echo "<td align='center'><font size='2'>".$row['importo']."</font></td>" ;
};
 echo " <td align='center' width='20'><font size='2'></font></td> 
     <td align='center'><font size='2'>".$row['data']."</font></td> 
     <td align='center'><font size='2'>".$row['tipo']."</font></td></tr>"; 
              $importo=mysql_result($result,$i,"importo"); 
    $totale_importo += $importo; 
    $i++;   
}   
echo "</table><br>";

provalo poi sappimi dire ciao
 
Ultima modifica:

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Ho fatto così:
PHP:
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr>

<th align='center' width=''><font size='2'>Cliente</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Numero</th>
<th align='center' width=''><font size='2'>Emissione doc.</th>
<th align='center' width=''><font size='2'>Codice cliente</th>
<th align='center' width=''><font size='2'>Importo euro</th>
<th align='center' width=''><font size='2'>-</th>
<th align='center' width=''><font size='2'>Data operazione</th>
<th align='center' width=''><font size='2'>Tipo operazione</th>
</tr>"; 
$totale_importo = 0;
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
        
    echo "<tr>
     <td align='center'><font size='2'>".$row['nome']."</font></td>
     <td align='center'><font size='2'>".$row['doc']."</font></td>
     <td align='center'><font size='2'>".$row['numero']."</font></td>
     <td align='center'><font size='2'>".$row['emissione']."</font></td>
     <td align='center'><font size='2'>".$row['codcliente']."</font></td>
     <td align='center'><font size='2'>".$row['importo']."</font></td>
     <td align='center' width='20'><font size='2'></font></td>
     <td align='center'><font size='2'>".$row['data']."</font></td>;

if($row['tipo']='ACCONTO'){  
     echo "<td align='center'><font size='2'><strong>".$row['tipo']."</strong></font></td></tr>";
}else{
    echo "<td align='center'><font size='2'>".$row['tipo']."</font></td></tr>";
};

              $importo=mysql_result($result,$i,"importo");
    $totale_importo += $importo;
    $i++;  
}  
echo "</table><br>";

Ma mi dà questo errore:
PHP:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /XXXX/pagamenti.php on line 68
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
PHP:
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr>

<th align='center' width=''><font size='2'>Cliente</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Numero</th>
<th align='center' width=''><font size='2'>Emissione doc.</th>
<th align='center' width=''><font size='2'>Codice cliente</th>
<th align='center' width=''><font size='2'>Importo euro</th>
<th align='center' width=''><font size='2'>-</th>
<th align='center' width=''><font size='2'>Data operazione</th>
<th align='center' width=''><font size='2'>Tipo operazione</th>
</tr>"; 
$totale_importo = 0;
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
     
     
     
     if ($row['tipo'] != 'ACCONTO') {    
    echo "<tr>
     <td align='center'><font size='2'>".$row['nome']."</font></td>
     <td align='center'><font size='2'>".$row['doc']."</font></td>
     <td align='center'><font size='2'>".$row['numero']."</font></td>
     <td align='center'><font size='2'>".$row['emissione']."</font></td>
     <td align='center'><font size='2'>".$row['codcliente']."</font></td>
     <td align='center'><font size='2'>".$row['importo']."</font></td>
     <td align='center' width='20'><font size='2'></font></td>
     <td align='center'><font size='2'>".$row['data']."</font></td>
     <td align='center'><font size='2'>".$row['tipo']."</font></td>";
     
}else{
    echo "<tr>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['nome']."</font></td>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['doc']."</font></td>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['numero']."</font></td>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['emissione']."</font></td>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['codcliente']."</font></td>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['importo']."</font></td>
     <td align='center' bgcolor='#FFFF00' width='20'><font size='2'></font></td>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['data']."</font></td>
     <td align='center' bgcolor='#FFFF00'><font size='2'>".$row['tipo']."</font></td>";
};
echo "</tr>";

              $importo=mysql_result($result,$i,"importo");
    $totale_importo += $importo;
    $i++;  
}  
echo "</table><br>";

Grazie mille!
 

giamma

Utente Attivo
4 Mag 2005
111
0
0
Ho fatto così:
PHP:
echo "<table style='border: 1px solid white' align='left' bgcolor='' border='1' width='100%' cellpadding='0' cellspacing='0'>"; 
echo "<tr>

<th align='center' width=''><font size='2'>Cliente</th>
<th align='center' width=''><font size='2'>Documento</th>
<th align='center' width=''><font size='2'>Numero</th>
<th align='center' width=''><font size='2'>Emissione doc.</th>
<th align='center' width=''><font size='2'>Codice cliente</th>
<th align='center' width=''><font size='2'>Importo euro</th>
<th align='center' width=''><font size='2'>-</th>
<th align='center' width=''><font size='2'>Data operazione</th>
<th align='center' width=''><font size='2'>Tipo operazione</th>
</tr>"; 
$totale_importo = 0;
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
        
    echo "<tr>
     <td align='center'><font size='2'>".$row['nome']."</font></td>
     <td align='center'><font size='2'>".$row['doc']."</font></td>
     <td align='center'><font size='2'>".$row['numero']."</font></td>
     <td align='center'><font size='2'>".$row['emissione']."</font></td>
     <td align='center'><font size='2'>".$row['codcliente']."</font></td>
     <td align='center'><font size='2'>".$row['importo']."</font></td>
     <td align='center' width='20'><font size='2'></font></td>
     <td align='center'><font size='2'>".$row['data']."</font></td>; // ti sei dimenticato il doppio apice

if($row['tipo']='ACCONTO'){  // e qui metteri == no =
     echo "<td align='center'><font size='2'><strong>".$row['tipo']."</strong></font></td></tr>";
}else{
    echo "<td align='center'><font size='2'>".$row['tipo']."</font></td></tr>";
};

              $importo=mysql_result($result,$i,"importo");
    $totale_importo += $importo;
    $i++;  
}  
echo "</table><br>";

Ma mi dà questo errore:
PHP:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /XXXX/pagamenti.php on line 68

manca un doppio apice sicuro e metterei == e non = sappimi dire se funziona ciao
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
o meglio così

PHP:
<style type="text/css">
.pinco{
background-color:#FF0000;
/*e tutto quello che vuoi*/
}
</style>

<?php
//...
while($row = mysql_fetch_array( $result )) { 
    $id=$row['id'];
    echo "<tr>
     <td align='center'><font size='2'>".$row['nome']."</font></td>
     <td align='center'><font size='2'>".$row['doc']."</font></td>
     <td align='center'><font size='2'>".$row['numero']."</font></td>
     <td align='center'><font size='2'>".$row['emissione']."</font></td>
     <td align='center'><font size='2'>".$row['codcliente']."</font></td>
     <td align='center'><font size='2'>".$row['importo']."</font></td>
     <td align='center' width='20'><font size='2'></font></td>
     <td align='center'><font size='2'>".$row['data']."</font></td>";
	 $stile="";
	 if($row['tipo']=='ACCONTO'){ $stile= "class='pinco'";}
	 echo "<td align='center' $stile ><font size='2'>".$row['tipo']."</font></td></tr>";
}
//......
?>

p.s.
usa i css (tra l'altro, es., il tag font è deprecato)
 

Trapano

Utente Attivo
27 Set 2012
238
0
16
48
Grazie. Adesso mi sbizzarrisco con modifiche per evidenziate alcuni dati.
 
Discussioni simili
Autore Titolo Forum Risposte Data
Shyson Cambiare colore font nel campo Javascript 26
G Cambiare colore ad un record database mysql MySQL 0
O Allo scroll cambiare colore di sfondo jQuery 0
DaveCricket [WordPress] [PHP] Cambiare il colore del link di una pagina attiva WordPress 3
V Cambiare colore ad un button HTML e CSS 3
Jonn [Javascript] Cambiare colore sfondo div allo scroll del mouse Javascript 3
V Aiuto su Stile CSS cambiare colore ad un modulo Joomla 1
R Vertex Template (jommla2.5): cambiare colore dell'header Joomla 12
A Cambiare colore bottone app Android Sviluppo app per Android 1
Shyson Cambiare colore al pulsante button HTML e CSS 6
D cambiare colore al testo il float PHP 1
Z Cambiare colore alla finestra degli avvisi CMS (Content Management System) 1
V Cambiare il colore della pagina con js [era: html con js] Javascript 11
B Cambiare colore riga dati estratti da mysql PHP 24
A Cambiare colore testo ??? Javascript 0
D Cambiare colore di un testo modificando php PHP 3
I Cambiare colore caratteri in echo PHP 1
S Mi aiutate a cambiare il colore di sfondo dei post ? HTML e CSS 2
P cambiare colore fondo (sfumato) Flash 3
U pannellino per cambiare colore alle pagine tramite css e JS Javascript 6
GennyX Cambiare colore alla tabella HTML e CSS 5
max1850 Fireworks: cambiare il colore di uno stile Webdesign e Grafica 9
G Come cambiare in Excel il colore cella attiva? Windows e Software 0
Eugene Cambiare colore sfondo DIV HTML e CSS 2
A cambiare il colore sfondo a tutto il sito HTML e CSS 6
F cambiare colore al passaggio del mouse HTML e CSS 1
F Url dinamiche da cambiare con categoria, subcategoria e title PHP 2
D Aiuto CSS in ELEMENTOR - Cambiare un testo CMS (Content Management System) 0
M Cambiare pennello a lavoro completo Photoshop 0
R Cambiare il nome dell'immagine dopo caricamento ftp HTML e CSS 0
Y cambiare sfondo di una pagina Javascript 1
E Cambiare lingua in Elements per Mac Mac e Software 2
R Non riesco a cambiare l'immagine di sfondo PHP 4
K Cambiare font size su echo stringa variabile PHP 24
V [PHP Symphony] Cambiare da ApcCache ad OpCache PHP 4
P Cambiare visualizzazione con JS Javascript 1
Web93 CAMBIARE TAG POST TITOLO DA H2 A H1 WordPress 1
L [PHP] cambiare gli if in un url semplice PHP 1
Domenico_Falco1 Cambiare url in un sito con pagine dinamiche Ajax 4
L Cambiare classi solo scroll up jQuery 2
Topografo Buon 2019 (Tutti gli altri hanno scritto "Salve a tutti", cerchiamo di cambiare) Presentati al Forum 1
joomeph Cambiare Nome Utente Supporto Mr.Webmaster 3
M [Visual Basic] Cambiare lo stato in checked delle checkbox richiamando dati dal database Visual Basic 6
Koboshi Cambiare il css di una pagina con tasto "on off" HTML e CSS 5
Licantropo [MySQL] Cambiare le date MySQL 4
B [Javascript] Cambiare classe ed aggiornare relativi eventi Javascript 3
L Cambiare nome pagina facebook Annunci servizi di Social Media Marketing 4
P [HTML] Wordpress - cambiare font di un tema WordPress 1
L APPARECCHIO VOIP DA CAMBIARE Adsl e Connettività 0
T cambiare formato in uscita timestamp Database 0

Discussioni simili