dtlhy0771 2016-10-05 19:07
浏览 109

如果字段为空,如何隐藏行?

I want to hide an entire row in the case of a field is empty:

example enter image description here

in the event that some field is empty, I want to hide all the entire row, either from javascript or from jquery. I tried some tricks, but nothing hides me the entire row. Is that possible?

            <table class="pmpro_affiliate_report" width="100%" cellpadding="0" cellspacing="0">
        <thead>
            <tr>                
                <th>Code</th>
                <th>Sub-ID</th>             
                <th>Name</th>       
                <th>Miembro</th>                        
                <th>Date</th>
                <th>Estado</th>             
                <th>Order Total</th>
            </tr>
        </thead>
        <tbody>
            <?php
                $sqlQuery = "SELECT a.code, o.affiliate_subid as subid, a.name, u.user_login, UNIX_TIMESTAMP(o.timestamp) as timestamp, o.total FROM $wpdb->pmpro_membership_orders o LEFT JOIN $wpdb->pmpro_affiliates a ON o.affiliate_id = a.id LEFT JOIN $wpdb->users u ON o.user_id = u.ID WHERE o.affiliate_id <> '' ";
                if($report != "all")
                    $sqlQuery .= " AND a.id = '" . esc_sql($report) . "' ";
                $affiliate_orders = $wpdb->get_results($sqlQuery);
                if(empty($affiliate_orders))
                {
                ?>
                    <tr><td colspan="6" class="pmpro_pad20">                    
                        <p>No affiliate signups have been tracked yet.</p>
                    </td></tr>
                <?php
                }
                else
                {
                    global $pmpro_currency_symbol;
                    // if($affiliate_orders->user_login != ''){
                    foreach($affiliate_orders as $order)
                    {
                    ?>
                    <tr>
                        <td><?php echo $order->code;?></td>
                        <td><?php echo $order->subid;?></td>
                        <td><?php echo stripslashes($order->name);?></td>
                        <td><?php echo $order->user_login;  if($order->user_login == '') {unset($order->user_login);}?></td>
                        <td><?php echo date(get_option("date_format"), $order->timestamp);?></td>
                        <td><?php echo $used_statuses;?></td>
                        <td><?php echo $pmpro_currency_symbol . $order->total;?></td>
                    </tr>
                    <?php
                    }
                }
            ?>
        </tbody>
        </table>
  • 写回答

4条回答 默认 最新

  • drjgk44268 2016-10-05 19:16
    关注

    I think you may just be better off iterating through the order values in your foreach, only returning the table row if all fields have a value. Otherwise you'll be outputting needless HTML with the only purpose of hiding it.

    That being said, if you were set on using JS/Jquery, you could do something like this...

    $('table tr').each(function() {  //For each table row
    
        //If there's an empty field
        if ($(this).find('td:empty').length) {
    
            //Remove the row
            $(this).remove(); 
    
        }
    });
    

    JSFiddle

    Your question was vague on whether or not it was a specific field, or any field. In the case of a specific field, you should really just do that in your PHP or SQL.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答