2016-11-04 1 views
-2

데이터베이스에서 데이터를 가져 와서 PHP의 jquery를 사용하여 html 테이블에 바인딩하려고합니다. 결과가 올바르게 표시됩니다. 하지만 나는 가져온 데이터를 편집 할 수 있어야한다는 의미로 내부 텍스트 상자에 데이터를 가져 오려고합니다. 제 요구를하십시오.데이터베이스에서 데이터를 가져와 PHP에서 jquery를 사용하여 html 테이블에 바인딩

내 코드는입니다.

<table class="table table-striped table-hover metable table-bordered" id="editable-sample"> 
           <thead> 
           <tr> 
        <th>Id</th> 
            <th>Customer Id</th> 
            <th>Item Number</th> 
            <th>Quantity</th> 

           </tr> 
           </thead> 
           <tbody> 
           <?php 
     foreach ($tempresults as $result) 
       { 
       ?> 
           <tr class=""> 
      <td><input type="text" name="order_id" id="order_id" value="<?php echo $result->order_id;?>"></td> 
      <td><input type="text" name="customer_id" id="customer_id" value="<?php echo $result->customer_id;?>"></td> 
      <td><input type="text" name="item_id" id="item_id" value="<?php echo $result->item_id;?>"></td> 
     <td><input type="text" name="count" id="count" value="<?php echo $result->count;?>"></td> 

           </tr> 

           <?php 
      } 
        ?> 
           </tbody> 
          </table> 
                   Thanks, 
+0

는 $ ("#의 ORDER_ID")'을 수행하여 텍스트 필드의 각각의 값을 설정 발 (result.correspondingdata가). '(당신의 데이터를 반환한다고 가정 정렬). –

답변

0

이 가장 우아한 해결책을하지 않을 수 있습니다,하지만 당신은 이것을 시도 않았다

$.ajax({ 

      type: "POST", 
      url: "add_temp_purchase", 
     cache: false, 
     data: 'itemnum='+itemnum+'&quantity='+quantity+'&customer_id='+customer_id, 
     dataType: "html", 
     success: function(returnhtml) { 
      //alert(customer_id); 
       $.ajax({ 

       type: "GET", 
       url: "gettempid", 
       cache: false, 
       data: 'customer_id='+customer_id, 
       dataType: "html", 
       beforeSend: function() { 
                        $('#metable').html('loading please wait...'); 
                          }, 
         success: function(htmldata) { 
       var order_id = order_id; 
        var customer_id = customer_id; 
        var item_id = itemnum; 
        var count = quantity; 

       alert(customer_id); 


       $(".metable").find('tbody').append('<tr><td>' + order_id + 
       '</td><td><input type="text">' + customer_id + 
         '</td><td><input type="text">' + item_id + 
       '</td><td><input type="text">' + count + 
        '</td></tr>'); 


         } 
         }); 

내 HTML 코드는? 당신의 아약스의 반환 된 데이터에서

$(".metable").find('tbody').append('<tr> 
    <td><input type="text" value="' + order_id + '"></td> 
    <td><input type="text" value="' + customer_id + '"></td> 
    <td><input type="text" value="' + item_id + '"></td> 
    <td><input type="text" value="' + count + '"></td> 
</tr>'); 
관련 문제