Page 1 of 1

Need help how to create mass data in database

Posted: Wed Jun 11, 2014 1:17 pm
by Gunner
Here's the case.
I want to make a map system for my turn based strategy game.
the world map will be like travian.. if you know good, but if you don't it's basically like X,Y based map.. but I have trouble in creating ALL of the XY's.. coz let's say I just want to have a maximum XY's of 25, so I have to create from -25,-25 to 25,25 and it's a hell a lot of amount of data.. I tried using excel once then so much dumb errors appeared when I exported it to SQL.. How do people actually do this? It's crazy, Travian has 400 to -400 of XY's and it's so insane if they do it manually, so I know that there's a programmed way, but I have no idea what people even call this to even search the keyword on google..

I am using MySQL btw

Re: Need help how to create mass data in database

Posted: Wed Jun 11, 2014 1:21 pm
by a_bertrand
Use excel, but use excel formula to actually create the SQL statement for you, and then copy paste that resulting SQL:

http://www.makewebgames.com/content.php ... ur-content

Re: Need help how to create mass data in database

Posted: Wed Jun 11, 2014 2:08 pm
by Gunner
damn man ur a genius!!!!!!!!!!!!!!!!!!! you gave me the idea now :D
thanks!!

Re: Need help how to create mass data in database

Posted: Wed Jun 11, 2014 2:13 pm
by Sharlenwar
All I did was create a function using PHP to input the data into an array and then into the database. For example:

Code: Select all

$xCoord=0;
  $yCoord=0;
  for ($yCoord=0; $yCoord < 9; $yCoord++) {
    for ($xCoord=0; $xCoord < 9; $xCoord++) {
      $data=array(1,$xCoord,$yCoord,1);
      $statement=$db->prepare("INSERT INTO mapTiles(mapId,xCoord,yCoord,tileId) VALUES(?,?,?,?)");
      $statement->execute($data);
    }
  }
  echo "Coords Inserted into mapTiles<br>";
So what I do here, is I sequence through my map grid that I intend to produce. My maps are 9x9 and so I have it go through each row, and each column and insert that into the DB. You could automate all of your content in this way. Then you would need to tweak each map to your liking. I intend to have an editor that will allow people with appropriate permission to access the maps and change the tiles around.

To make a long story short, I wrote some code to insert the data in.

Re: Need help how to create mass data in database

Posted: Wed Jun 11, 2014 3:58 pm
by tourmaline
Lacking PHP, I cobbled this together once in an excel cell function on an unused column:

Code: Select all

="insert into items_122812 values('" &A203 &"','" &B203 &"','" &C203 &"','" &D203 &"','" &E203 &"','" &F203 &"','" &G203 &"','" &H203 &"', '" &I203 &"','" &J203 &"','" &K203 &"','" &L203 &"','" &M203 &"','" &N203 &"','" &O203 &"', '" &P203 &"','" &Q203 &"','" &R203 &"','" &S203 &"','" &T203 &"','" &U203 &"','" &V203 &"', '" &W203 &"','" &X203 &"','" &Y203 &"','" &Z203 &"','" &AA203 &"','" &AB203 &"','" &AH203 &"', '" &AD203 &"','" &AI203 &"','" &AF203 &"','" &AG203 &"');"
Pretty lame, but it was the quickest an easiest for what I needed.

Re: Need help how to create mass data in database

Posted: Wed Jun 11, 2014 4:16 pm
by Sharlenwar
Nothing is lame, we all have different ways of doing the same thing. I figure it is always good to see how others have done it and share. You never know when you might need that one bit of info to help move you along. :D