display color according to value in the database

0

hello friends I am showing the status of a query and I add a specific color but I notice it as very old, that kind of model and I would like to show it a little different the old model is the example with the blue color and how I would like to show it is the example with the yellow color:

here my query:

<?php

  class crud
 {
private $db;

function __construct($DB_con)
{
    $this->db = $DB_con;
}


/* paging */

public function dataview($query)
{
    $stmt = $this->db->prepare($query);
    $stmt->execute();

    if($stmt->rowCount()>0)
    {
        while($linea=$stmt->fetch(PDO::FETCH_ASSOC))
        {


        $status_color = array(
                    'Pendiente' => '#b71c1c',
                    'Procesando' => '#1565c0',
                    'Procesado' => '#fbc02d'
                          );

            echo "<tr>
            <td>$linea[nombres])</td>
            <td>$linea[apellidos]</td>
            <td>$linea[totalpago]</td>            
            <td align=center class='center-align white-text' 
            bgcolor='". $status_color[$linea['status']] ."'>$linea[status]
         </td>";

          ?>

the div I use to show it in a different way than the current one

  'echo "<td align=center><div class='col s10 card-panel yellow darken-2 center'><p class='black-text'>$linea[status]</h5></div></p>";'

    
asked by yoclens 21.06.2017 в 21:42
source

1 answer

1

Your Code would be the following:

<?php

  class crud
 {
private $db;

function __construct($DB_con)
{
    $this->db = $DB_con;
}


/* paging */

public function dataview($query)
{
    $stmt = $this->db->prepare($query);
    $stmt->execute();

    if($stmt->rowCount()>0)
    {
        while($linea=$stmt->fetch(PDO::FETCH_ASSOC))
        {


        $status_color = array(
                    'Pendiente' => '#b71c1c', /*<-- En vez de color pones el nombre de la clase*/
                    'Procesando' => 'yellow',
                    'Procesado' => '#fbc02d'/*<-- En vez de color pones el nombre de la clase*/
                          );

            echo "<tr>
            <td>$linea[nombres])</td>
            <td>$linea[apellidos]</td>
            <td>$linea[totalpago]</td>            
            <td align=center><div class='col s10 card-panel '". $status_color[$linea['status']] ."' darken-2 center'><p class='black-text'>$linea[status]</p></div></td>";

          ?>
    
answered by 21.06.2017 / 22:07
source