获取单个数据JQUERY

时间:2018-06-05 19:20:07

标签: php jquery

想象一下,我tbl_customer中有3个数据然后如果单击按钮视图,模式将显示数据' s。如果我点击的按钮有数据,它就可以正常工作,那么问题是,如果按钮没有数据模式没有显示。但我想显示模态,即使我的button中没有数据。请帮帮我解决这个问题,谢谢!

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

以下是代码:

<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 个答案:

没有答案