使用php没有记录列时如何禁用按钮? [英] How to disable button when there are no records column using php?

查看:78
本文介绍了使用php没有记录列时如何禁用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果数据库的特定列中没有记录,我想禁用该按钮.我在echo语句View和Cancel中有两个按钮.我正在从数据库中检索值并显示.我想禁用没有记录的那一行的按钮.您能帮我吗?

I want to disable the button if there are no records in a specific column in the database. I have two buttons in echo statement View and cancel. I am retrieving the value from the database and displaying. I want to disable button of that row which is no records. Would you help me in this?

<th>Name</th>  
 <th>Email</th>
 <th>Mobile</th>
  <th>action</th>



  <?php
    if (isset($all_records->num_rows) > 0) {
    // output data of each row
    while($row = $all_records->fetch_assoc()) {
         $name=$row['name'];
         $email=$row['email'];
        $mobile=$row['mobile']; 

        if ($email == 0 || $mobile==0) {
            //disable btn
            }
        else{
            //enable btn
        }   

        echo "
        <tr>
        <td>{$name}</td>
        <td>{$email}</td>
        <td>{$mobile}</td>
        <td class='in_set_btn'><a href='' class='btn'>view</a> <a href=''  class='btn'>Cancel</a></td>
        </tr>
  ";
   }
  }

推荐答案

<?php
    if (isset($all_records->num_rows) > 0) {
    // output data of each row
    while($row = $all_records->fetch_assoc()) {
        $name=$row['name'];
        $email=$row['email'];
        $mobile=$row['mobile']; 
        $emailBtn = "<a href='' class='btn'>view</a>";
        $mobileBtn = "<a href='' class='btn'>cancel</a>";
        if (empty($email)) {
            $emailBtn = "<a disabled href='' class='btn'>view</a>";
        }
        if (empty($mobile)) {
            $mobileBtn = "<a disabled href='' class='btn'>cancel</a>";
        }

        echo "
            <tr>
            <td>{$name}</td>
            <td>{$email}</td>
            <td>{$mobile}</td>
            <td class='in_set_btn'>".$emailBtn.$mobileBtn."</td>
            </tr>
        ";
   }
?>

这篇关于使用php没有记录列时如何禁用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆