【问题标题】:Disable button when db is populated enable when null on javascript填充 db 时禁用按钮在 javascript 上为 null 时启用
【发布时间】:2014-02-13 13:31:48
【问题描述】:

我有一个名为 material 的数据库表 材料:

mat_id    mat_name     status
1          bolts         
2          steel      approved

当 status = 'approved' 时,如何使我的按钮或 href 链接禁用 在我的 html 表上?

喜欢:

option        mat_id   material name
show button     1         bolts
no button       2         steel

我的 html/php 代码:

    <?php 


    $resource=mysql_query("Select * from material",$con);

    while($result2=mysql_fetch_array($resource))
        { 

        ?>
     <tr>
    <th>option</th>
    <th>mat_id</th>
    <th>material name</th>
    </tr>

     <tr>
  <td align="center">
<?php 
$id = $rows['reqraw_id'];
if($rows['status']=="")
{
   echo '<a href="addstockout.php?id=$id" > Update </a>';
} ?>
</td>
    <td><?php echo $result2['mat_id']; ?></td>
    <td><?php echo $result2['mat_name']; ?></td>
    </tr>
        <?php };?>

这一行有问题

echo '<a href="addstockout.php?id=$id" > Update </a>';

它没有从 db 中获取 id 数组。

【问题讨论】:

    标签: javascript php html mysql select


    【解决方案1】:
    ...
    <?php if($result2['status'] == 'approved') { ?>
        <td><button disabled="true">Button</button></td>         
    <?php 
    } else{ ?>
        <td><button>Button</button></td>
     <?php } ?>
    
    ...
    

    【讨论】:

      【解决方案2】:
      if($result2['status']=="" OR $result2['status']===NULL)
      {
         echo '<button type="button">Click Me!</button>';
      }else{
         echo '<button type="button" disabled>Click Me!</button>';
      }
      

      【讨论】:

        【解决方案3】:
        <td><?php echo ($result2['status']===NULL)?"button here":"disabled"; ?></td>
        

        【讨论】:

        • 您可能应该将此作为一个单独的问题提出,而不是更改您原来的问题,但是...echo '&lt;a href="addstockout.php?id='. $id. '" &gt; Update &lt;/a&gt;';
        【解决方案4】:

        我认为应该这样做:

        代替

        <td>button</td>
        

        放:

        <?php
        
        echo '<td><button ';
        if(!($result2['status']==="approved"))
        {
           echo 'disabled="true"';
        }
        echo '>Click</button></td>';
        
        ?>
        

        【讨论】:

        • 如果statusnull,OP 希望它启用。即:if($result2['status']===NULL)
        猜你喜欢
        • 2021-02-12
        • 2013-10-29
        • 1970-01-01
        • 2014-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多