Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 打印数据库表并根据其子行颜色为父行上色_Php_Jquery_Html Table - Fatal编程技术网

Php 打印数据库表并根据其子行颜色为父行上色

Php 打印数据库表并根据其子行颜色为父行上色,php,jquery,html-table,Php,Jquery,Html Table,PHP页面必须显示数据库表的内容。在另一个表中,我将使用该值相应地打印行并显示为子行 $result = pg_query($conn, "SELECT *,'SENT' as direction FROM table1 WHERE identification LIKE '%$identification%' AND expedition LIKE '$expedition' order by date DESC LIMIT '$limit' "); 这将在一段时间内打印此类表格: whil

PHP页面必须显示数据库表的内容。在另一个表中,我将使用该值相应地打印行并显示为子行

$result = pg_query($conn, "SELECT *,'SENT' as direction FROM table1 WHERE identification LIKE '%$identification%' AND expedition LIKE '$expedition' order by date DESC LIMIT '$limit' ");
这将在一段时间内打印此类表格:

while ($row = pg_fetch_row($result)) {

    $sql2 = pg_query($conn, " SELECT quantity FROM expedition WHERE identification='$row[2]' ");
    $row2 = pg_fetch_row($sql2);
    $color="white";
    if ($row2[0] == "-1") { $color="red";}
    if ($row2[0] == "1") { $color="green";}
    if ($row2[0] == "0") { $color="grey";}

echo "<tr bgcolor=\"$color\">
    <td><button class=\"btn btn-info\" type=\"button\" data-toggle=\"collapse\" data-target=\"#$row[2]\">+</button></td>
    <td>row[0]</td>
    <td>row[1]</td>
    <td>row[2]</td>
    <td>row[3]</td>
    <td>row[4]</td>
    <td>...and more</td>
    </tr>";

echo "<tr><td colspan=9><div style=\"background-color:$color\" id=\"$row[2]\" class=\"collapse\">$row2[0]</div></td></tr> ";
while($row=pg\u fetch\u row($result)){
$sql2=pg_query($conn,“从远征中选择数量,其中标识=“$row[2]”);
$row2=pg_fetch_行($sql2);
$color=“白色”;
如果($row2[0]==“-1”){$color=“red”}
如果($row2[0]=“1”){$color=“green”;}
如果($row2[0]=“0”){$color=“grey”;}
回声“
+
第[0]行
第[1]行
第[2]行
第[3]行
第[4]行
……还有更多
";
回显“$row2[0]”;
我正在使用引导添加一个按钮,单击该按钮后,将打开一个隐藏行,内容为
$sql2
。我将直接在
之后打印查询

请注意,第一个查询为
row[]
,第二个查询为
row2[]

问题:
如果第二个查询包含多个结果,并且在所有情况下标识都不是PK(因此可能会有更多),则我无法为每一行打印其子项的颜色

  • 我需要扩展第二个查询来管理WHILE循环,以便通过标识提取其父查询的所有值

  • 如果sql2包含-1、1或0,则必须相应地绘制父级及其自身

  • 如果sql2包含不同的值,则必须将它们都漆成红色(错误)
  • 最明显的选择是在第一段末尾移动SQL2,而在本例中,我可以使用SQL2和我想要的所有记录。 就像使用数组或FOR结构一样

    但是,移动代码不允许打印所有行,因为html已经编写好了

    在这种情况下,我认为我需要Jquery在已经写入值之后突出显示它们。 我对Jquery一无所知,如果有任何建议或帮助,我将不胜感激

    附上一张图片来展示我所取得的成就,绿色条只包含一个子元素,正如上面的代码。请原谅这个丑陋的界面!