I’m new to using the data type POINT in MYSQL so I wanted to test an output to a table in PHP but I’m getting the error “Undefined index”. How can I fix the this error and display the points in the table?
The error message
Notice: Undefined index: my_point in C:\xampp\htdocs\view.php on line 23
(The points do not show in the table. How can I fix this?)
MYSQL Table
/*Table structure for table 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 Code*
<?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);
?>
You need a column alias for your two calculated columns:
Access them as
$row['my_point_x'], $row['my_point_y'].Without column aliases, they exist in your
$rowas$row['x( my_point )'], $row['y (my_point)'], exactly as they appeared in yourSELECTlist.