创建新数组仅用于打印表中的选中行

我有一个由查询填充的表,通过一个简单的foreach循环。现在,我想打印该表的选中行,但是当前可打印的表位于另一个 ,因为它们具有完全不同的格式和样式,并且第二个表(实际上我能够打印的表)使用与result_array完全相同的查询获取数据。<div>


我正在尝试弄清楚如何将第一个表的检查行转换为单独的数组,并使用该数组而不是第二个数组的查询,因此只能打印已检查的行。


我一直在尝试打印第一张桌子本身,但它没有像我想要的那样显示,它使用了很多彩色墨水(这是没有问题的)。很长一段时间以来,我一直在尝试不同的方法,但我没有意识到它们在不同的容器上(完全是一个愚蠢的错误,ik),它只是想到了制作这个新数组来实现它的想法,但只是不知道如何继续。


<div class="tab-pane" id="TLL">

<table class="table table-bordered" style="color: Black" id="table-3">

<?php

$control_info= $this->db->query("select * 

                                from controlsemanal 

                                where vendedora = 'Taller' 

                                and Indicador != '1' 

                                and Indicador !='100' 

                                ORDER BY FIELD (Id_Status,1,3,4,5,6,2,7,0) ");

?>

<thead> etc etc </thead>


<tbody>

<?php

$arr_loop = $control_info;

foreach ($arr_loop->result_array() as $row) {

<tr> <th>

<div>

<input type="checkbox" name="check[]" value="">

</div>

</th>

etc etc

</tr>

</tbody>

</table>

这是可打印的表格


<div style="display:none" id="imprimeme3">

$control_info= $this->db->query("select * 

                                from controlsemanal 

                                where vendedora = 'Taller' 

                                and Indicador != '1' 

                                and Indicador !='100' 

                                ORDER BY FIELD (Id_Status,1,3,4,5,6,2,7,0) ");

<table>

foreach ($control_info->result_array() as $row) {

etc etc

}

</table>


<center>

<button style="border:0;background:#04998A;color:white;width:550px;height:50px;font-size: 30px" onclick="imprimir3();">

<b>IMPRIMIR</b>

</button>

</center>

</div>


打印第二张表格的功能


function imprimir3() {

        var objeto = document.getElementById('imprimeme3'); 

        var ventana = window.open('', '_blank'); 

        ventana.document.write(objeto.innerHTML);        

        ventana.document.close();

        ventana.print();

        ventana.close();

    }

我试图在这里使代码尽可能短,以免成为麻烦,任何帮助将不胜感激,非常感谢。


陪伴而非守候
浏览 165回答 1
1回答

扬帆大鱼

好的,在第一段代码中创建表单,使用主键作为复选框的值:<div class="tab-pane" id="TLL"><table class="table table-bordered" style="color: Black" id="table-3"><?php$control_info= $this->db->query("select *&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from controlsemanal&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where vendedora = 'Taller'&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and Indicador != '1'&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and Indicador !='100'&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY FIELD (Id_Status,1,3,4,5,6,2,7,0) ");?><thead> etc etc </thead><tbody><?php$arr_loop = $control_info;foreach ($arr_loop->result_array() as $row) {?><tr> <th><div><input type="checkbox" name="check[]" value="<?php echo $row['referencia']; ?>"></div></th>etc etc</tr><?php} // I guess foreach ends here?></tbody></table>然后,在您的第二个表格(处理$ _POST表单)中,仅获得标记的项目:check必须是一个数组,包含 每个标记的项目reference未标记的复选框不会与表单一起发送从他们那里列出一个列表以创建过滤器“ref1,ref2,...雷夫克斯”我猜你的参考列是数字,如果没有,评论,我会修复查询$referencias = (isset($_POST['check'])) ? implode(', ', $_POST['check']) : '';// Create your query, filtering by $references$control_info= $this->db->query("select *&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from controlsemanal&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where vendedora = 'Taller'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and referencia IN ($referencias)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY FIELD (Id_Status,1,3,4,5,6,2,7,0) ");// Create your table here
打开App,查看更多内容
随时随地看视频慕课网APP