从数据库中提取的数据不正确

时间:2015-07-20 13:45:53

标签: javascript php jquery html json

我遇到了从数据库中提取的数据可视化问题,然后进入Json文件。当我查看页面时,表中的数据显示不正确。这是代码:

HTML代码:这里我们有一个包含第一个静态行的表,其他的是动态的。

2

然后,我们有PHP代码:

public class Parent {
       int num = 10;

       public void method(){
           System.out.println("Parent method");
       }
}

public class Child extends Parent {
    int num = 20;  // Why this declaration is allowed ?
     public void method(){
       System.out.println("Child method");
     }

    public static void main(String[] args) {

        Parent f = new Child();
        Child f2 = new Child();
        System.out.println(f.num);
        System.out.println(f2.num);
    }

}

这是读取数据并将其附加到HTML页面的代码:

<div class="col-sm-10 col-sm-push-1 div-1">
<table class="datatable table table-primary table-striped table-bordered table-hover">
    <thead>
    <tr class="row">
        <td>ID</td>
        <td>Nome</td>
        <td>Cognome</td>
        <td>Indirizzo</td>
        <td>Email</td>
        <td>Tipo contatto</td>
        <td>Telefono 1</td>
        <td>Telefono 2</td>
        <td>Telefono 3</td>
    </tr>
    </thead>

    <tbody id="tab-0">
    <!--inserimento dinamico contenuti-->
    </tbody>
</table>
<!--spazio per il form-->

最后,我们得到的Json数据应该在行中形成:

 private $hookUp;
 private $sql;
 private $sql2;
 private $sql3;
 private $sql4;

 public function __construct()
 {
 $this->hookUp = UniversalConnect::doConnect();

$this->sql = "SELECT * FROM cliente";
$this->sql2 = "SELECT * FROM accettazione";
$this->sql3 = "SELECT * FROM riparazione";
$this->sql4 = "SELECT * FROM operatore";

// Tabella cliente

$response = array();
$data = array();

if ($result = $this->hookUp->query($this->sql)) {
    while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {

        $data[] = array("id" => "<tr class='row'><td>" . $row['id'] . "</td>",
                        "nome" => "<td>" . $row['nome'] . "</td>",
                        "cognome" => "<td>" . $row['cognome']. "</td>",
                        "indirizzo" => "<td>" . $row['indirizzo'] . "</td>",
                        "email" => "<td>" . $row['email'] . "</td>",
                        "tipo_contatto" => "<td>" . $row['tipo_contatto'] . "</td>",
                        "telefono_1" => "<td>" . $row['telefono_1'] . "</td>",
                        "telefono_2" => "<td>" . $row['telefono_2'] . "</td>",
                        "telefono_3" => "<td>" . $row['telefono_3'] . "</td></tr>");

        $response['cliente'] = $data;

        $fp = fopen("../lista.json", "w");
        fwrite($fp,json_encode($response));
        fclose($fp);
    }
}  

如果我用Firebug检查动态生成的行,我发现这行是以这种方式打印的:

 var name;
 var value;

 var count_cliente = 0;
 var count_accettazione = 0;
 var count_riparazione = 0;
 var count_operatore = 0;

 $('.sidebar-menu a').click(function (e) {
     hideContentDivs();
var tmp_div = $(this).parent().index();
$(".main-sections div").eq(tmp_div).show();

$.getJSON("lista.json", function (json) {

    if (tmp_div == 0) {
        var data = json.cliente;

        if (count_cliente == 0) {

            for (i = 0; i < data.length; i++) {
                var obj = data[i];

                for (var key in obj) {
                    name = key;
                    value = obj[key].toString();

                    $("#tab-0").append(name + " : " + value);
                }
            }
            count_cliente++;
        }

但是结束tr标签应该在行的末尾。

问题是什么,你能帮我理解错误吗?

0 个答案:

没有答案