New question

Question:

Date: 18-02-2020 02:41:16 (In Spanish)

Como puedo pintar una variable en php?[Resolved]

hola, estoy renegando y no se como lograr pintar un campo de una tabla dependiendo del estado intente con javasript pero no dio resultado, dejo mi php para ver si me pueden ayudar. Gracias!!!

<?php

include "../config/config.php";//Contiene funcion que conecta a la base de datos

$action = (isset($_REQUEST['action']) && $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
if (isset($_GET['id'])){
$id_del=intval($_GET['id']);
$query=mysqli_query($con, "SELECT * from ticket where id='".$id_del."'");
$count=mysqli_num_rows($query);

if ($delete1=mysqli_query($con,"DELETE FROM ticket WHERE id='".$id_del."'")){
?>
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
×</button>
<span class="glyphicon glyphicon-ok"></span> <strong>Aviso</strong>
<hr class="message-inner-separator">
<p>
Datos eliminados con exito.</p>

</div>
<?php
}else {
?>
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
×</button>
<span class="glyphicon glyphicon-hand-right"></span> <strong>Mensaje de alerta</strong>
<hr class="message-inner-separator">
<p>
Lo siento algo ha salido mal intenta nuevamente.</p>
</div>
<?php
} //end else
} //end if
?>

<?php
if($action == 'ajax'){
// escaping, additionally removing everything that could be (html/javascript-) code
$q = mysqli_real_escape_string($con,(strip_tags($_REQUEST['q'], ENT_QUOTES)));
$aColumns = array('title');//Columnas de busqueda
$sTable = "ticket";
$sWhere = "";
if ( $_GET['q'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
$sWhere .= $aColumns[$i]." LIKE '%".$q."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
$sWhere.=" order by created_at desc";
include 'pagination.php'; //include pagination file
//pagination variables
$page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
$per_page = 10; //how much records you want to show
$adjacents = 4; //gap between pages after number of adjacents
$offset = ($page - 1) * $per_page;
//Count the total number of row in your table*/
$count_query = mysqli_query($con, "SELECT count(*) AS numrows FROM $sTable $sWhere");
$row= mysqli_fetch_array($count_query);
$numrows = $row['numrows'];
$total_pages = ceil($numrows/$per_page);
$reload = './expences.php';
//main query to fetch the data
$sql="SELECT * FROM $sTable $sWhere LIMIT $offset,$per_page";
$query = mysqli_query($con, $sql);
//loop through fetched data
if ($numrows>0){

?>

<table id="tabla" class="table table-striped table-hover jambo_table bulk_action">
<thead>
<tr class="headings ">
<th class="column-title">Asunto </th>
<th class="column-title">Usuario </th>
<th class="column-title">Prioridad </th>
<th class="column-title">Estado </th>
<th>Fecha</th>
<th class="column-title no-link last"><span class="nobr"></span></th>

</tr>
</thead>
<tbody>
<?php
while ($r=mysqli_fetch_array($query)) {
$id=$r['id'];
$created_at=date('d/m/Y', strtotime($r['created_at']));
$description=$r['description'];
$title=$r['title'];
$username=$r['user_id'];
$priority_id=$r['priority_id'];
$status_id=$r['status_id'];
$kind_id=$r['kind_id'];
$category_id=$r['category_id'];

$sql = mysqli_query($con, "select * from user where id=$username");
if($c=mysqli_fetch_array($sql)) {
$name_username=$c['username'];
}

$sql = mysqli_query($con, "select * from priority where id=$priority_id");
if($c=mysqli_fetch_array($sql)) {
$name_priority=$c['name'];
}

$sql = mysqli_query($con, "select * from status where id=$status_id");
if($c=mysqli_fetch_array($sql)) {
$name_status=$c['name'];

}


?>
<input type="hidden" value="<?php echo $id;?>" id="id<?php echo $id;?>">
<input type="hidden" value="<?php echo $title;?>" id="title<?php echo $id;?>">
<input type="hidden" value="<?php echo $description;?>" id="description<?php echo $id;?>">

<!-- me obtiene los datos -->
<input type="hidden" value="<?php echo $kind_id;?>" id="kind_id<?php echo $id;?>">
<input type="hidden" value="<?php echo $username;?>" id="username<?php echo $id;?>">
<input type="hidden" value="<?php echo $category_id;?>" id="category_id<?php echo $id;?>">
<input type="hidden" value="<?php echo $priority_id;?>" id="priority_id<?php echo $id;?>">
<input type="hidden" value="<?php echo $status_id;?>" id="status_id<?php echo $id;?>">


<tr class="even pointer"><!--MUESTRO LOS DATOS EN LA TABLA TICKET -->
<td><?php echo $title;?></td>
<td><?php echo $name_username; ?></td>
<td><?php echo $name_priority; ?></td>
<td><?php echo $name_status;?></td>
<td><?php echo $created_at;?></td>
<td ><span class="pull-center">
<a href="#" class='btn btn-default' title='Responder' onclick="obtener_datos('<?php echo $id;?>');" data-toggle="modal" data-target=".bs-example-modal-lg-udp"><i class="glyphicon glyphicon-edit"></i>Responder</a>

</tr>
<?php
} //en while
?>
<tr>
<td colspan=6><span class="pull-right">
<?php echo paginate($reload, $page, $total_pages, $adjacents);?>
</span></td>
</tr>
</table>
</div>
<?php
}else{
?>
<div>
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
x</button>
<span class="glyphicon glyphicon-info-sign"></span> <strong>Mensaje</strong>
<hr class="message-inner-separator">
<p>
No hay datos para mostrar.</p>
</div>
</div>
<?php
}
}
?>
Tags: AJAX - PHP - Question Votes: 0 - Answers: 3 - Views: 15 Share on: Google Facebook Twitter LinkedIn Link
 

Answers:

  • Date: 18-02-2020 06:28:58 Hola amigo, necesito mas información.
    Cual es la variable con la información que deseas colorear y cuando se cumpla que condición la quieres pintar ?
      Votes: 0 - Link answer
     
  • Date: 18-02-2020 06:36:00 Podrías crear la validación desde tu PHP, por ejemplo:

    En base a la condición qué esté cumpliendo

    if ($condicion == 1){
    $color = "amarillo";
    }else{
    $color = "rojo";
    }

    Con la variable obtenida ($color) la imprimis en tu html, ejemplo:

    <div class="<?php echo color; ?>">
    ...........
    </div>

    Ahora con css, manipulas el color, ejemplo:

    .rojo{
    background: red;
    }
      Votes: 1 - Link answer
     
  • Date: 18-02-2020 07:25:59 buenísimo mejor imposible, gracias por la pronta respuesta!!!   Votes: 0 - Link answer
     
To actively participate in the community first must authenticate, enter the system.Sign In
 
frjcbbae garagebible.com