有关创建和查询MySQL临时表的问题

时间:2014-07-02 16:50:50

标签: php mysql sql json mysqli

我遇到从临时表中获取json数据的问题。正如您所看到的,我尝试在charts_econo处生成临时表$query,在第二次查询$query2中我尝试将表解析为JSON,但我什么也没得到。

这是我的php文件

<?PHP
include 'conconfig.php';
$con = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$collm = $_POST['column'];
$query = "CREATE TEMPORARY TABLE IF NOT EXISTS `charts_econo` (
          `econo_sum_projects` decimal(12,7) NOT NULL,
          `econo_sum_powerline` decimal(12,7) NOT NULL,
          `econo_sum_roads` decimal(12,7) NOT NULL,
          `econo_sum_cost` decimal(12,7) NOT NULL
          ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AS(SELECT COUNT(`project`),
                                                   SUM(`powerline_length`),
                                                   SUM(`road_length`),
                                                   SUM(`cost_per_year`)
                                                   FROM `econo` WHERE c_1000=1;";
$con->query($query);
$query2 = "SELECT * FROM `charts_econo`" ;
$results = $con->query($query2);
if($results) {
  while($row = $results->fetch_assoc()) {
     $json=json_encode($row);
  }
}
$con->close();
echo $json;
?>

0 个答案:

没有答案