2012-06-29 47 views
2

我是新来的在MYSQL中使用数据类型POINT,所以我想用PHP测试输出到表中,但是我收到错误“Undefined index”。我如何解决这个错误并在表格中显示点?PHP中的未定义索引和MYSQL中的数据类型POINT

错误消息 注意:未定义指数:my_point在C:\ XAMPP \ htdocs中上线\ view.php 23

(该点没有在表中显示我怎样才能解决。此?)

MySQL表

为表

/*表结构highcharts_php */

  CREATE TABLE `highcharts_php` (
       `id` int(11) NOT NULL AUTO_INCREMENT, 
       `run_name` varchar(150) DEFAULT NULL, 
       `my_point` POINT DEFAULT NULL, 
       `cur_timestamp` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
       PRIMARY KEY (`id`) 

      ) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=latin1; 
       SET time_zone='+00:00'; 
      /*Data for the table `highcharts_php` */ 

      insert into highcharts_php (`id`,`run_name`,`cur_timestamp`,`my_point`) values (1, 'SSTP Keystone COOPER','2012-06-28 00:00:01', GeomFromText(' POINT(0.6 70.18) ')) 

* PHP代码 *

  <?php 
      $con = mysql_connect("localhost","root","xxxxxxxx"); 
      if (!$con) 
       { 
       die('Could not connect: ' . mysql_error()); 
       } 

      mysql_select_db("graph", $con); 
      /*$result = mysql_query("SELECT * FROM highcharts_php");*/ 
      $result = mysql_query("SELECT run_name,cur_timestamp, x(my_point), y(my_point) FROM highcharts_php LIMIT 0 , 30")or die 
      (mysql_error()); 
      echo "<table border='1'> 
      <tr> 
      <th>run_name</th> 
      <th>my_point</th> 
      <th>cur_timestamp</th> 
      </tr>"; 

      while($row = mysql_fetch_array($result)) 
       { 
       echo "<tr>"; 
       echo "<td>" . $row['run_name'] . "</td>"; 
       echo "<td>" . $row['my_point'] . "</td>"; 
       echo "<td>" . $row['cur_timestamp'] . "</td>"; 
       echo "</tr>"; 
       } 
      echo "</table>"; 

      mysql_close($con); 
      ?> 

回答

5

你需要为你的两个计算列列别名:

$result = mysql_query(" 
    SELECT 
    run_name, 
    cur_timestamp, 
    /* Column aliases via AS */ 
    x(my_point) AS my_point_x, 
    y(my_point) AS my_point_y 
    FROM highcharts_php LIMIT 0 , 30") or die(); 

访问他们为$row['my_point_x'], $row['my_point_y']

没有列别名,它们在您的$row中作为$row['x(my_point)'], $row['y (my_point)']存在,正如它们出现在您的SELECT列表中一样。

+0

谢谢你的工作! – mgrobins

1

别名从X()Y()使用AS,像这样的返回值:

X(my_point) AS x_value, Y(my_point) AS y_value 

然后访问它们在PHP中为:

$row['x_value'] 
$row['y_value'] 

否则,你将有访问柱:

$row['X(my_point)'] 

或者类似的东西 - 见the example的文档,看看如何列名根据您的查询是动态生成的。

+0

感谢您的反馈! – mgrobins

1
SELECT run_name, 
cur_timestamp, 
CONCAT(x(my_point), ' ', y(my_point)) as my_point 
FROM highcharts_php LIMIT 0 , 30 
+0

感谢您的反馈! – mgrobins