【问题标题】:How can i change the color of a table row depending of the mysql result with php?如何根据 php 的 mysql 结果更改表行的颜色?
【发布时间】:2011-12-07 21:32:04
【问题描述】:

我想改变我的桌子的颜色。这取决于该字段中的数据是否与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 );
?>

【问题讨论】:

  • 可能没有“251902”键?
  • 对于 td 你也可以使用
  • 尝试设置 $serial 或者只是检查你的 html 源代码,你就会明白是你输入的数组,或者没有。为什么会有 array_key_exists("251902",$ser) ?我认为应该是 array_key_exists($serial,$ser)
  • 嗨,有“251902”键,但它不会改变颜色。如果我用 $serial 更改 "251902" 是一样的
  • 检查你的 html 输出,是否有 style=\"background-color: ? 或没有

标签: php mysql arrays while-loop


【解决方案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>

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签