代码php无法正常工作

时间:2016-06-26 11:09:25

标签: php

data_show_project.php

{"aaData":[["aaaah","2"]]}

运行文件<?php header("Content-type: text/html; charset=UTF-8"); header('Cache-Control: no-cache'); header('Pragma: no-cache'); header('Expires: 0'); include("connect_project.php"); //รับ pk ที่มาจากหน้า display $id = $_GET['id']; $where = "INNER JOIN requirement_tbl ON requirement_tbl.req_id = testcase_tbl.req_id AND requirement_tbl.p_id = testcase_tbl.p_id WHERE testcase_tbl.p_id = $id"; $sql = "SELECT requirement_tbl.req_id AS req_id,req_name,COUNT(tc_id) AS tc_id FROM testcase_tbl $where"; $result = runSQL($sql); $numrow = countRec('requirement_tbl.req_id','testcase_tbl',$where); if($numrow>0){ $json = ""; $json .= "{"; $json .= "\"aaData\":["; $rc = false; while ($row = mysql_fetch_array($result)) { if ($rc) $json .= ","; $json .= "["; $json .= "\"".$row['req_name']."</a>"."\""; $json .= ",\"".$row['req_detail']."\""; $json .= ",\"".number_format($row['tc_id'])."\"]"; $rc = true; } $json .= "]"; $json .= "}"; echo $json; } ?>

和data_show_req.php

{"aaData":[["bbbbb","2"],["ccccc","0"]]}

我想运行档案{{1}}
但是没有工作

[enter image description here

1 个答案:

答案 0 :(得分:0)

我会建议您使用数组。

<?php
$arr = array(
        "aaData" => array(
                array('bbbbb',2), array("cccccc",0)
              )
);

echo json_encode($arr);
?>

结果:eval.in

用你的案子;它应该是这样的,

<?php
$arr = array();
if($numrow>0){
    $arr['aaData'] = array();
    $i =0;
        while ($row = mysql_fetch_array($result)) {
        $arr['aaData'][0][$i] =   array(
                        $row['p_name'],
                        number_format($row['tc_id'])            
                    );          
        $i++;
    }

    echo json_encode($arr);
}
?>

我认为你的'countRec(...)'函数返回错误的结果。 你可以试试'mysql_num_rows($ result)'

最好停止使用mysql连接。请检查PDO

我希望这有帮助。