如何根据 php 的 mysql 结果更改表行的颜色?
我想改变我的桌子的颜色。这取决于该字段中的数据是否与 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ó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°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 );
?>
im trying to change the color of my table. It depends on if the data in that field is the same that in other table of mysql db. it changes the color but i know that is not ok. i think the problem is that the array is in a while loop.
this is my code:
<?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ó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°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 );
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我找到了问题的解决方案。
这里是:
Ok i found the solution to my question.
here it is: