Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2012
    Messaggi
    54

    Cambia colore se minore di 0

    Salve a tutti, ho un profondo vuoto di memoria.
    Ho questo codice
    Codice PHP:
         <?php  
       $hostname 
    "*";$dbname "*";$user "*";$pass ""
    ;$db = new PDO ("mysql:host=$hostname; dbname=$dbname"$user$pass);   if(isset($_POST['check'])){$date_str $_POST['data'];
    $converted date("Y-m-d"strtotime($date_str));
    $sQuery22 "SELECT maschera FROM utente where maschera like 'TOPOLINO' and data ='$converted'"
    $rResult22 $db->query($sQuery22)->fetchAll();  
    echo 
    "<table max-width:100px; border=\"2\"> \n"; echo " <tbody>";
    echo 
    "<thead>        <tr><th>Tipologia</th><th>Prenotati</th><th>Disponibilità</th></tr>    </thead> "
    echo 
    " <tr><td align =center width=200>",TOPOLINO,"</td>";  echo "<td align =center><p>",count($rResult22),"</p></td>"
    echo 
    "<td align =center>1</td>";
    echo 
    " </tbody></table>"
    }
    ?>
    Vorrei sapere come fare per rendere di colore rosso quando il result22 è uguale ad 1.
    Grazie.
    Ultima modifica di lelemkop; 14-05-2018 a 10:11

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Mettendo dove vuoi applicare il colore un if() nel quale controlli se il valore di $rResult22 è = 1 e se lo è stampi il codice per definire il colore.

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2012
    Messaggi
    54
    ho provato a fare così ma niente...
    codice:
         <?php
    
    $db = new PDO ("mysql:host=$hostname; dbname=$dbname", $user, $pass);
       if(isset($_POST['check'])){
    $date_str = $_POST['data'];
    $converted = date("Y-m-d", strtotime($date_str));?>
    <h3 align="center">Per la data &nbsp;<?php $data = $_POST['data'];
    $converted1 = date("d/m/Y", strtotime($data));echo $converted1; ?> è disponibile il seguente materiale</h3>
    <style>
    td.subzero {color : #FF0000;}
    </style>
    <?php
    $sQuery22 = "SELECT maschera FROM utente where maschera like 'TOPOLINO' and data ='$converted'"; 
    $rResult22 = $db->query($sQuery22)->fetchAll(); 
     
    echo "<table max-width:100px; border=\"2\"> \n"; 
    echo " <tbody>";
    echo "<thead>
            <tr><th>Tipologia</th><th>Prenotati</th><th>Disponibilità</th></tr>
        </thead> "; 
    echo " <tr><td align =center width=200>",TOPOLINO,"</td>";  
    echo "<td align =center <?php if($rResult22<2) echo 'class=subzero'; ?><p>",count($rResult22),"</p></td>"; 
    echo "<td align =center>1</td>";
    echo " </tbody></table>";
     }?>
    non cambia niente

  4. #4
    Utente di HTML.it
    Registrato dal
    Nov 2012
    Messaggi
    54

    [Risolto] cambia colore se maggiore di 0

    ho risolto così.
    Codice PHP:

    $db = new PDO ("mysql:host=$hostname; dbname=$dbname", $user, $pass);   if(isset($_POST['check'])){$date_str = $_POST['data'];
    $converted = date("Y-m-d", strtotime($date_str));?>
    <?php$sQuery22 "SELECT maschera FROM utente where maschera like 'TOPOLINO' and data ='$converted'";
     
    $rResult22 $db->query($sQuery22)->fetchAll(); 
    $conta count($rResult22);
    echo 
    "<table max-width:100px; border=\"2\"> \n"; echo " <tbody>";
    echo 
    "<thead>        <tr><th>Tipologia</th><th>Prenotati</th><th>Disponibilità</th></tr>    </thead> ";
     echo 
    " <tr><td align =center width=200>",TOPOLINO,"</td>"
     if(
    $conta>0)echo '<td align=center style="font-weight: bold; color: red;">'.$conta.'</td>';
    else echo 
    '<td align= center style="font-weight: bold; color: black;">'.$conta.'</td>';
     echo 
    "<td align =center>1</td>";echo " </tbody></table>"; }?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.