dp926460 2018-06-05 19:20
浏览 89

获取单个数据JQUERY

Imagine I have 3 data in my tbl_customer then If I click the button view, the modal will show with the data's. It's working if the button I clicked has data, Then the problem is, if the button has no data the modal didn't show. But I want to show the modal even I have no data in my button. Please help me out of this problem, thankyou!

Button: <button type="button" onclick="return chk('.$row['id'].')" class="btn btn-warning btn-xs">Add features</button>

Here's the code:

<script src = "http://code.jquery.com/jquery-1.9.1.js"></script>'

<?php 
$db = mysqli_connect("localhost", "root", "", "psbr");
$rooms_f = mysqli_query($db, "SELECT * FROM room_f"); 

while($row = mysqli_fetch_assoc($rooms_f)) { ?> 
<button type="button" onclick="return chk('.$row['id'].')" class="btn btn-warning btn-xs">Add features</button>
<?php } ?>

  function chk(id)
  {
    var roomid = document.getElementById('text_id_' + id).value;
    var dataString = 'roomid='+ roomid;
    $.ajax({
      type: "post",
      url: "fetch_single3.php",
      data:dataString,
      cache:false,
      success: function(data){

       $("#modal_features").hide();
       $("#modal_sample").slideDown();
       $("#modal_sample").html(data);
      }
    });
    return false;
  }

fetch_single3

    <?php 

$db = mysqli_connect('localhost', 'root', '', 'psbr');
$rooms = mysqli_query($db, "SELECT * FROM rooms");

    $roomid = $_POST['roomid'];
    $query = mysqli_query($db, "SELECT * FROM room_f WHERE room_id='$roomid'"); 

?>
<link rel="stylesheet" type="text/css" href="css/feature-design.css">
<div id="modal_sample">
    <h4 class="h4" style="margin: 3%;">Room Features</h4>
    <button class="btn btn-info button">Add Feature</button>
<table id="features_table">
  <tr>
    <th width="20%">ID</th>
    <th width="49%">Feature</th>
    <th>Action</th>
  </tr>
<?php while ($row = mysqli_fetch_array($query)) { ?>
  <tr>
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['feature']; ?></td>
    <td><button class="btn btn-warning btn-xs">Update Feature</button> &nbsp;<button class="btn btn-warning btn-danger btn-xs ">Delete feature</button></td>
  </tr>
  <div class="add_modal" id="add_modal">
        <h4 style="margin: 5%; ">Add Feature</h4>
        <hr>
        <label style="margin: 1%;">Enter Feature name</label>
        <input type="text" id="text_featurename" name="text_featurename">
        <input type="hidden" id="text_featureid" name="text_featureid" value="<?php echo $row['room_id']; ?>">
        <input type="submit" name="submit" value="Submit" onclick="return add()" id="submit">
        <button class="btn btn-default cbtn_addm">Close</button>
    </div>
  <?php } ?>
</table>
<button type="button" id="btn_c"class="btn_c">Close</button>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题