繁体   English   中英

数据表和JEditable

[英]Datatables and JEditable

只是从php,datatables和jeditable入手,我可以加载我的表并看起来不错,当我单击表中的记录时,它可以编辑记录,而当我查看表中的dataOut.php文件时,我正在获取数据。 chrome开发人员工具,但未传递记录标识符。

 <script type="text/javascript"> $(document).ready(function() { $('#users').dataTable( { } ); /* Init DataTables */ var oTable = $('#users').dataTable(); /* Apply the jEditable handlers to the table */ oTable.$('td').editable( 'dataOut.php', { "callback": function( sValue, y ) { var aPos = oTable.fnGetPosition( this ); oTable.fnUpdate( sValue, aPos[0], aPos[1] ); window.location.reload(); }, "submitdata": function ( value, settings ) { return { "row_id": this.parentNode.getAttribute('id_user'), "column": oTable.fnGetPosition( this )[2] } }, "height": "14px", "width": "100%" } ); } ); </script> 
 <table id="users" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>id</th> <th>First Name</th> <th>Last Name</th> <th>Username</th> <th>Name</th> <th>Role Code</th> </tr> </thead> <tbody> <?php $sql = "SELECT * FROM `users`"; foreach ($conn->query($sql)as $row){ echo '<tr>'; echo '<td>' . $row['id_user'] . '</td>'; echo '<td>' . $row['firstname'] . '</td>'; echo '<td>' . $row['lastname'] . '</td>'; echo '<td>' . $row['username'] . '</td>'; echo '<td>' . $row['realname'] . '</td>'; echo '<td>' . $row['role'] . '</td>'; echo '</tr>'; } ?> </tbody> <tfoot> <tr> <td>id</td> <td>iFirstname</td> <td>Lastname</td> <td>Username</td> <td>Name</td> <td>Role Code</td> </tr> </tfoot> </table> 

当我将姓氏从Lewis更改为Lane时,这是chrome开发人员的结果

array(4){[“” value“] => string(4)” Lane“ [” id“] => string(0)”“ [” row_id“] => string(0)”“ [” column“] =>字符串(1)“ 2”}

我不确定我是否理解您的问题,但是我注意到一个错误,我怀疑这可能是您的问题。

在您的foreach循环中,您正在循环通过mysqli_result对象的$conn->query() 您需要调用fetch_assoc方法。 另外,这需要通过while循环而不是foreach循环来完成。 这是因为fetch_assoc是获取与查询匹配的下一行的函数,而不是返回包含所有匹配行的大数组。 当没有更多的行时,它返回null并因此结束while循环。 尝试这个:

 <script type="text/javascript"> $(document).ready(function() { $('#users').dataTable( { } ); /* Init DataTables */ var oTable = $('#users').dataTable(); /* Apply the jEditable handlers to the table */ oTable.$('td').editable( 'dataOut.php', { "callback": function( sValue, y ) { var aPos = oTable.fnGetPosition( this ); oTable.fnUpdate( sValue, aPos[0], aPos[1] ); window.location.reload(); }, "submitdata": function ( value, settings ) { return { "row_id": this.parentNode.getAttribute('id_user'), "column": oTable.fnGetPosition( this )[2] } }, "height": "14px", "width": "100%" } ); } ); </script> 
 <table id="users" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>id</th> <th>First Name</th> <th>Last Name</th> <th>Username</th> <th>Name</th> <th>Role Code</th> </tr> </thead> <tbody> <?php $sql = "SELECT * FROM `users`"; while($row = ($conn->query($sql))->fetch_assoc()) { echo '<tr>'; echo '<td>' . $row['id_user'] . '</td>'; echo '<td>' . $row['firstname'] . '</td>'; echo '<td>' . $row['lastname'] . '</td>'; echo '<td>' . $row['username'] . '</td>'; echo '<td>' . $row['realname'] . '</td>'; echo '<td>' . $row['role'] . '</td>'; echo '</tr>'; } ?> </tbody> <tfoot> <tr> <td>id</td> <td>iFirstname</td> <td>Lastname</td> <td>Username</td> <td>Name</td> <td>Role Code</td> </tr> </tfoot> </table> 

http://php.net/manual/en/mysqli-result.fetch-assoc.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM