Guest User

Untitled

a guest
Aug 19th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. This is how my HTML looks like:
  2.  
  3. <div class="row">
  4. <div class="col-xs-12">
  5.  
  6. <div class="box">
  7. <div class="box-header">
  8. <h3 class="box-title">Data Table With Full Features</h3>
  9. </div>
  10. <!-- /.box-header -->
  11. <div class="box-body">
  12. <table id="example1" class="table table-bordered table-striped">
  13. <thead>
  14. <tr class="row">
  15. <th>ID</th>
  16. <th>Nome</th>
  17. <th>Cognome</th>
  18. <th>Indirizzo</th>
  19. <th>Email</th>
  20. <th>Tipo contatto</th>
  21. <th>Telefono 1</th>
  22. <th>Telefono 2</th>
  23. <th>Telefono 3</th>
  24. <th>Azioni</th>
  25. </tr>
  26. </thead>
  27. <tbody id="tab-0">
  28.  
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- /.box-body -->
  33. </div>
  34. <!-- /.box -->
  35. </div>
  36. <!-- /.col -->
  37. </div>
  38. <!-- /.row -->
  39.  
  40. And this is how the JSON data in composed in PHP
  41.  
  42. if ($result = $this->hookUp->query($this->sqlA)) {
  43. while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
  44.  
  45. $id = $row['id'];
  46.  
  47. $data[] = array("id" => "<td>" . $row['id'] . "</td>",
  48. "nome" => "<td id='nome:" . $id . "' contenteditable='true'>" . $row['nome'] . "</td>",
  49. "cognome" => "<td id='cognome:" . $id . "' contenteditable='true'>" . $row['cognome'] . "</td>",
  50. "indirizzo" => "<td id='indirizzo:" . $id . "' contenteditable='true'>" . $row['indirizzo'] . "</td>",
  51. "email" => "<td id='email:" . $id . "' contenteditable='true'>" . $row['email'] . "</td>",
  52. "tipo_contatto" => "<td id='tipo_contatto:" . $id . "' contenteditable='true'>" . $row['tipo_contatto'] . "</td>",
  53. "telefono_1" => "<td id='telefono_1:" . $id . "' contenteditable='true'>" . $row['telefono_1'] . "</td>",
  54. "telefono_2" => "<td id='telefono_2:" . $id . "' contenteditable='true'>" . $row['telefono_2'] . "</td>",
  55. "telefono_3" => "<td id='telefono_3:" . $id . "' contenteditable='true'>" . $row['telefono_3'] . "</td>",
  56. "edit" => "<td>" . '<a id="' . $row['id'] . '" class="delete" href="#"><i class="fa fa-fw fa-remove"></i></a>
  57. <a id="' . $row['id'] . '" class="edit" href="#"><i class="fa fa-fw fa-edit"></i>' . "</a></td>");
  58.  
  59. $response['cliente'] = $data;
  60.  
  61. $fp = fopen("../lista.json", "w");
  62. fwrite($fp, json_encode($response));
  63. fclose($fp);
  64. }
  65. }
  66.  
  67. This is how the JSON data is appended:
  68.  
  69. $.getJSON("lista.json", function (json) {
  70.  
  71. if (json.cliente) {
  72.  
  73. for (i = 0; i < json.cliente.length; i++) {
  74. var obj = json.cliente[i];
  75.  
  76. var output = "<tr class='row'>";
  77.  
  78. for (var key in obj) {
  79. name = key;
  80. value = obj[key].toString();
  81.  
  82. output += value;
  83. }
  84.  
  85. output += "</tr>";
  86.  
  87. console.log(output);
  88.  
  89. $("#tab-0").append(output);
  90. }
  91.  
  92. }
  93.  
  94. [...] close brackets.
Advertisement
Add Comment
Please, Sign In to add comment