我希望在字段为空的情况下隐藏整行:
如果某个字段为空,我想隐藏整个行,无论是来自javascript还是来自jquery。我尝试了一些技巧,但整个行都没有隐藏任何东西。这可能吗?
<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>
答案 0 :(得分:0)
我认为你可能会更好地迭代foreach
中的订单值,只有在所有字段都有值的情况下才返回表格行。否则,您将输出不必要的HTML,其唯一目的就是隐藏它。
话虽如此,如果你开始使用JS / Jquery,你可以做这样的事情......
$('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();
}
});
您的问题是否是特定字段或任何字段的含糊不清。对于特定字段,您应该在PHP或SQL中执行此操作。
答案 1 :(得分:0)
你不应该为此而需要js,只需在回显tr
之前添加一个if语句foreach($affiliate_orders as $order)
{ if( !empty(.......) ){
答案 2 :(得分:0)
你可以通过检查sql查询,不选择有空字段的值
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 <> '',
o.affiliate_subid <> '',
a.name <> '',
u.user_login <> '',
o.timestamp <> '',
o.total <> ''
答案 3 :(得分:-2)
[UPDATE] 是的JQuery classList.add('invisible');
我认为你需要JQuery bootstrap才能做到这一点 检查http://api.jquery.com/toggleclass/
我在我的项目中使用它并且它正在工作
function changeVisibility(){
$secret.classList.add("invisible");
}