yourichi Posted August 24, 2011 Share Posted August 24, 2011 Hi there, trying to create a function more out of lazyness an timesaving than anything im sure it has to do with something combining the use of INSERT and x++ in an array, but im failing at figuring out the right way of doing it to achieve the right combination of effects. in simple need to create a 600x600 grid of co-ordinates where x starts at 1, ending in 600 with y starting at 1 and ending in 600 so basically a cubed set of entrys, (360,000 rows) not even sure thats possible lol.. the table only needs to contain the colums of id, x , y , ownerid (where id is auto inc) any suggestions, as you can tell its a pain-staking long case of affairs to create with a manual VERY long sql statement, trying to figure out a better way of doing this. help please? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/245610-creating-table-entrys/ Share on other sites More sharing options...
cunoodle2 Posted August 24, 2011 Share Posted August 24, 2011 <?php //start the insert string $query = "INSERT INTO `grid` (x,y) VALUES "; $x = 1; //create the loop to build the query for ($y = 1; $y <= 600; $y++) { $query .= '($x, $y), '; //increase $x ONLY when $y is 600 if ($y == 600) { $x ++; if ($x < 601) { $y = 1; //likely you may want to insert 600 records here as otherwise your query MAY get too long } } } //first check to see if the query ends in a "," if (substr(trim($query), -1) == ",") { $query = substr($query,0,-1); //if so then remove it $query .= ";"; } //then execute the insert here mysql_query($query); mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245610-creating-table-entrys/#findComment-1261509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.