2013-05-09 27 views
0

我想使用JQuery Datatables唯一地链接表的每一行。我遇到的问题是我可以如何存储,或者查看每个数据表的每一行的唯一链接。表体动态地从数据库中创建为这样连接数据表中的一行

echo " 
    <table id='table_id' class='table table-striped'> 
    <thead> 
    . . . 
    </thead> 
    <tbody> 
"; 

while($row) { 
    // The uniquely value to represent the link to each row is 
    // <a href ='rideinfo?PostID=$row[6]'></a> 
    echo "   
     <tr> 
      <td>$row[1]</td> 
      <td>$departDate</td> 
      <td>$departTime</td> 
      <td>$row[2]</td> 
      <td>$returnDate</td> 
      <td>$returnTime</td> 
      <td>$$row[5]</td> 
     </tr>         
    "; 
    $row = $result->fetch_row(); 
} 

jQuery的是

$(document).ready(function() { 
    var oTable = $('#table_id').dataTable({ 
     "sPaginationType": "bootstrap"   
    });  

    $("#table_id tbody tr").live('click',function() { 
     // I am not sure here how to store and get the id for each row 
     document.location.href = "?PostID=" + id;  
    });          
}); 

如何让每一行相应该值将非常感激任何帮助。

回答

0

给你的while循环一样

while($row) { 
// The uniquely value to represent the link to each row is 
// <a href ='rideinfo?PostID=$row[6]'></a> 
echo "   
    <tr id='<?php echo $row[6];?>'> 
     <td>$row[1]</td> 
     <td>$departDate</td> 
     <td>$departTime</td> 
     <td>$row[2]</td> 
     <td>$returnDate</td> 
     <td>$returnTime</td> 
     <td>$$row[5]</td> 
    </tr>         
"; 
$row = $result->fetch_row(); 
} 

,并把jQuery的像

$("#table_id tbody tr").on('click',function() { 
    var id = $(this).attr('id'); 
    document.location.href = "?PostID=" + id;  
}); 

上更换现场,因为它已经过时了。

Ratherthan是把一个链接上额外的“TD”,并给予链接到您想要的页面一样

<td><a href="my_url?postId=<?php echo $row[6];?>">LINK</a></td> 
+0

是它为你工作..? – Gautam3164 2013-05-09 05:46:40

+0

这有效,但我得到的问题是分页,出于某种原因链接只在第一页上工作 – user1875195 2013-05-09 05:47:05

+0

给我分页脚本.. ?? – Gautam3164 2013-05-09 05:48:03