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

发布于 2024-12-10 09:30:52 字数 3740 浏览 0 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回首观望 2024-12-17 09:30:52

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

//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>

Ok i found the solution to my question.
here it is:

//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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文