如何禁用href

时间:2013-12-06 00:54:09

标签: php jquery mysqli

如果purchase_order中的数量达到purchase_request中的total_quantity,我想禁用<a class="fancybox" href="addrfq.php?pn=' . $row["counter"] . '"></a>

我有两个表:Purchase_request和Purchase_order。当数量达到其最大数量时,我想禁用HREF。我怎么能这样做?

Purchase_Request

counter | total_quantity 

000004  |  3000  
000172  |  100  
000007  |  500  
000005  |  300

PURCHASE_ORDER

counter | quantity 

000004  |  2999  
000004  |  1  

Pr.php

<?php
$mysqli = new mysqli("localhost", "root", "", "app");

    $result = $mysqli->query("
    select 
        a.counter,
        a.total_quantity, a.pr,
        a.total_quantity - b.quantity balance,
        b.quantity, b.unit, b.unit_cost,
        b.unit_cost * b.quantity total_amount,
        c.item_name
    from
        (select counter, pr,
        sum(total_quantity) total_quantity
        from purchase_request
        group by counter) a 
    left outer join
        (select counter, unit, unit_cost,
        sum(quantity) quantity
        from purchase_order 
        group by counter) b 
    on a.counter= b.counter
    inner join
        (select counter, item_name
        from app 
        group by counter) c 
    on a.counter= c.counter
    group by a.counter
    order by a.pr
    ");
    echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;" border="1px">
        <thead>
        <tr>
        </tr>
        </thead>';
        echo'<tbody>';
    $i=1;   
while($row = $result->fetch_assoc()){
    echo'<tr>
            <td>'.$i++.'</td>
            <td align="center"><a class="fancybox" href="addrfq.php?pn=' . $row["counter"] . '"><img src="images/add.png" border="0" width="10" height="10" title="Add Purchase Order"></a></td>
            <td>'.$row['counter'].'</td>
            <td>'.$row['pr'].'</td>
            <td>'.$row['item_name'].'</td>
            <td>'.$row['unit'].'</td>
            <td>'.$row['unit_cost'].'</td>
            <td>'.$row['quantity'].'</td>
            <td>'.$row['total_quantity'].'</td>
            <td>'. number_format($row['total_amount'], 2, '.', ',') .'</td>
            <td>'.$row['balance'].'</td>
        </tr>';
       }
    echo "</tbody></table>";

?>

4 个答案:

答案 0 :(得分:1)

想一想:p

if($row['quantity']<$row['total_quantity'])
{  
    echo "<a href='whatever.php'>Link example</a>";
} else {
    echo "<a href='#'>No sir</a>";
}

答案 1 :(得分:0)

尝试

if ($row['quantity'] < $row['total_quantity']) {
    echo "<a href='abc.php'>Link</a>";
} else {
    echo "<a href='javascript:void(0)'>Disabled link</a>";
}

答案 2 :(得分:0)

为什么不在'addrfq.php'文件中,在添加/处理查询之前,检查它们是否达到了最大值。如果它们未达到最大值,则继续处理查询。

答案 3 :(得分:0)

更改此行:

<td align="center"><a class="fancybox" href="addrfq.php?pn=' . $row["counter"] . '"><img src="images/add.png" border="0" width="10" height="10" title="Add Purchase Order"></a></td>

要:

<td align="center"><a class="fancybox" href="' . ($i < $row['total_quantity'] ? 'addrfq.php?pn=' . $row["counter"] : 'javascript:void(0)') . '"><img src="images/add.png" border="0" width="10" height="10" title="Add Purchase Order"></a></td>