php - how can I INSERT a random Point with X|Y which is not yet in my Mysql Database -


yeah.

i have bases in coordinates. around center. want add 1 more base, @ unique coordinates, near other bases. have thought far:

insert `mydb`.`base`     (`idbase`, `coordinate_x`, `coordinate_y`)     values (null,             '(floor( 1 + rand( ) *((select max(coordinate_x))+1)))',             '(floor( 1 + rand( ) *((select max(coordinate_y))+1)))'            ); 

idbase autoincrement, thats why insert null

this far how choose point in area want them have. allready thought of making unique index coordinates. how can go sure, new base created @ new point?

i prefer not doing while-loop in php, think wouldnt nice sollution.

edit:

that did not work, cant make subselect in insert statement..

perhaps using insert..select construct instead of ill-formed subqueries in side quotes:

insert `mydb`.`base`     (`idbase`, `coordinate_x`, `coordinate_y`)     select null,            floor( 1 + rand( ) * (max(coordinate_x)+1) ),            floor( 1 + rand( ) * (max(coordinate_y)+1) )         mydb.base; 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -