如何根据mysql结果用php更改表行的颜色?

时间:2011-10-14 16:07:19

标签: php mysql arrays while-loop

我试图改变我的桌子的颜色。这取决于该字段中的数据是否与mysql db的其他表中的数据相同。它会改变颜色,但我知道这不好。我认为问题是数组处于while循环中。

这是我的代码:

<?php
$counter2 = 0;
$result = mysql_query( "SELECT * FROM prod_defectuoso WHERE ticket_id = '$ticket_id'"     );
$nr = mysql_num_rows( $result );
if(empty($nr))
{
echo("
<tr>
<td colspan='3'><center>No hay Pieza o Partes Cambiados</center></td>
</tr>
");
}

echo("
<div style=\"margin-bottom:-5px\">
<table width=\"50%\" border=\"0\" cellspacing=\0\ cellpadding=\2\ class=\"dtable\"     align=\"center\">
<tr>
<th width='10%' nowrap><center>#</center></th>
<th width='10%' nowrap><center>Descripci&oacute;n (Cambio)</center></th>
<th width='10%' nowrap><center>Serie</center></th>
<th width='10%' nowrap><center>Diagnostico</center></th>
<th width='10%' nowrap><center>Comentario</center></th>
<th width='10%' nowrap><center>Usuario</center></th>
<th width='10%' nowrap><center>Nombre del Courier</center></th>
<th width='10%' nowrap><center>N&deg;Remito</center></th>
<th width='10%' nowrap><center>Devuelto el:</center></th>
<th width='10%' nowrap><center>Creado el:</center></th>");
if($thisuser->isAdmin()) {
echo("
<th width='10%' nowrap><center>Borrar</center></th>
</tr>
");
}
while( $row = mysql_fetch_array( $result ))
{
$counter2;
$desc = $row["desc"];
$serial = $row["serial"];
$state = $row["state"];
$comment = $row["comment"];
$user = $row["user"];
$nomcourier = $row["nomcourier"];
$nremito = $row["nremito"];
$fdevolucion = $row["fdevolucion"];
$created = $row["created"];
$counter2 = $counter2 + 1;

//Mostramos prod_cambio.serial que no tiene "match" de valores con skus.serial
$show = mysql_query("select prod_defectuoso.serial from prod_defectuoso left join skus on >prod_defectuoso.serial = skus.serial where skus.serial is null");
$showme= mysql_fetch_array($show);
$ser = array ($row["serial"]);
print_r($ser);
echo '<br>'.((array_key_exists($serial,$ser))? 'item found' : 'item not found');

echo("<tr>
<td width='10%' nowrap>$counter2</td>
<td width='10%' nowrap>$desc</td>");
$color="#df8f8f";
if (array_key_exists("251902",$ser)){
echo("
<td width='200' style=\"background-color:$color\">$serial</td>
<td width='10%' nowrap>$state</td>
<td width='10%' nowrap>$comment</td>
<td width='10%' nowrap>$user</td>
<td width='10%' nowrap>$nomcourier</td>
<td width='10%' nowrap>$nremito</td>
<td width='10%' nowrap>$fenvio</td>
<td width='10%' nowrap>$created</td>
");
}
else{
echo("
<td width='200' nowrap>$serial</td>
<td width='10%' nowrap>$state</td>
<td width='10%' nowrap>$comment</td>
<td width='10%' nowrap>$user</td>
<td width='10%' nowrap>$nomcourier</td>
<td width='10%' nowrap>$nremito</td>
<td width='10%' nowrap>$fdevolucion</td>
<td width='10%' nowrap>$created</td>
");
}
if($thisuser->isAdmin()) {
echo("
<td width='10%' nowrap><a href='piopa.php?pdefectuoso_id=$pdefectuoso_id&id=$ticket_id'' >onClick=' return confirm(\"Esta seguro que desea BORRAR el inventario?\");'>Borrar</a>
</td>
</tr>
");
}
}
echo ("</table>");
echo("
<div aling=\"center\">*Los datos en Rojo no aparecen la Base de Datos</div>
");
mysql_free_result( $result );
?>

1 个答案:

答案 0 :(得分:-1)

好的,我找到了问题的解决方案。 这是:

//Mostramos prod_cambio.serial que no tiene "match" de valores con skus.serial
$show = mysql_query("select prod_defectuoso.serial from prod_defectuoso left join skus on prod_defectuoso.serial = skus.serial where skus.serial is null");
//$shows = array();
//$ser = array($shows["serial"]);
while ($showme= mysql_fetch_assoc($show)){
$shows[] = $showme['serial'];
$mem2 = $row['serial'];
//print_r($showme);
}
echo("<tr>
<td width='10%' nowrap>$counter2</td>
<td width='10%' nowrap>$desc</td>");
$color="#df8f8f";
//if ($showme = $serial){
if (in_array($mem2, $shows)) {    
echo("
<td width='200' style=\"background-color:$color\">$serial</td>