Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is how my HTML looks like:
- <div class="row">
- <div class="col-xs-12">
- <div class="box">
- <div class="box-header">
- <h3 class="box-title">Data Table With Full Features</h3>
- </div>
- <!-- /.box-header -->
- <div class="box-body">
- <table id="example1" class="table table-bordered table-striped">
- <thead>
- <tr class="row">
- <th>ID</th>
- <th>Nome</th>
- <th>Cognome</th>
- <th>Indirizzo</th>
- <th>Email</th>
- <th>Tipo contatto</th>
- <th>Telefono 1</th>
- <th>Telefono 2</th>
- <th>Telefono 3</th>
- <th>Azioni</th>
- </tr>
- </thead>
- <tbody id="tab-0">
- </tbody>
- </table>
- </div>
- <!-- /.box-body -->
- </div>
- <!-- /.box -->
- </div>
- <!-- /.col -->
- </div>
- <!-- /.row -->
- And this is how the JSON data in composed in PHP
- if ($result = $this->hookUp->query($this->sqlA)) {
- while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
- $id = $row['id'];
- $data[] = array("id" => "<td>" . $row['id'] . "</td>",
- "nome" => "<td id='nome:" . $id . "' contenteditable='true'>" . $row['nome'] . "</td>",
- "cognome" => "<td id='cognome:" . $id . "' contenteditable='true'>" . $row['cognome'] . "</td>",
- "indirizzo" => "<td id='indirizzo:" . $id . "' contenteditable='true'>" . $row['indirizzo'] . "</td>",
- "email" => "<td id='email:" . $id . "' contenteditable='true'>" . $row['email'] . "</td>",
- "tipo_contatto" => "<td id='tipo_contatto:" . $id . "' contenteditable='true'>" . $row['tipo_contatto'] . "</td>",
- "telefono_1" => "<td id='telefono_1:" . $id . "' contenteditable='true'>" . $row['telefono_1'] . "</td>",
- "telefono_2" => "<td id='telefono_2:" . $id . "' contenteditable='true'>" . $row['telefono_2'] . "</td>",
- "telefono_3" => "<td id='telefono_3:" . $id . "' contenteditable='true'>" . $row['telefono_3'] . "</td>",
- "edit" => "<td>" . '<a id="' . $row['id'] . '" class="delete" href="#"><i class="fa fa-fw fa-remove"></i></a>
- <a id="' . $row['id'] . '" class="edit" href="#"><i class="fa fa-fw fa-edit"></i>' . "</a></td>");
- $response['cliente'] = $data;
- $fp = fopen("../lista.json", "w");
- fwrite($fp, json_encode($response));
- fclose($fp);
- }
- }
- This is how the JSON data is appended:
- $.getJSON("lista.json", function (json) {
- if (json.cliente) {
- for (i = 0; i < json.cliente.length; i++) {
- var obj = json.cliente[i];
- var output = "<tr class='row'>";
- for (var key in obj) {
- name = key;
- value = obj[key].toString();
- output += value;
- }
- output += "</tr>";
- console.log(output);
- $("#tab-0").append(output);
- }
- }
- [...] close brackets.
Advertisement
Add Comment
Please, Sign In to add comment