php - Complex MySQL join from old table to new -


i have old database named locations table inside named locations.

this table has 7 variables: id (int, index), approved(int), city(text), country(text), heading(double), lat(double), lng(double).

i have new database named complexity. database has new table named gsvraw

i need copy old table new table, gets tricky:

the new database going use spatial indexing of mysql can search within polygon later. in new database, instead of lat, lng, want add new column that's called location.

the example statement creating new column:

alter table gsvraw add location point not null; create spatial index location on gsvraw (location); 

this example statement inserting new value location column:

insert gsvraw (location) values( geomfromtext( 'point(40 -100)' )); 

40 , -100 lat , lng.

any ideas?

i wasted hour each of 3 different "guru's" here @ mit , literally got nowhere.

the server i'm running causing major problems using python , mysqldb out.

hopefully out there smarter , can raw sql statements.

i'm running on mac apache mysql , php using mamp pro. causes trouble solutions work straight php , sql @ point. ideas?

solution:

<?php $con = mysql_pconnect("localhost","username","password"); if (!$con)   {   die('could not connect: ' . mysql_error());   } mysql_select_db("database1", $con);   $result = mysql_query("select * database1 ")  or die(mysql_error());    $con2 = mysql_pconnect("localhost","username","password"); if (!$con2)   {   die('could not connect: ' . mysql_error());   } mysql_select_db("complexity", $con2);  while($row = mysql_fetch_array( $result )) {      mysql_query("insert table1 (id, approved, city, country, heading, location) values ('".$row['id']."', '".$row['approved']."', '".$row['city']."', '".$row['country']."', '".$row['heading']."', pointfromtext('point(".$row['lng']." ".$row['lat'].")'))", $con2);  }  ?> 

have tried pointfromtext function?

set location = pointfromtext(concat('point(',latitude,' ',longitude,')')); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -