Need help how to create mass data in database

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Gunner
Posts: 276
Joined: Sun Aug 14, 2011 12:07 am

Need help how to create mass data in database

Post 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
Skype: mrvictordiaz
User avatar
a_bertrand
Posts: 1537
Joined: Mon Feb 25, 2013 1:46 pm

Re: Need help how to create mass data in database

Post 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
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Gunner
Posts: 276
Joined: Sun Aug 14, 2011 12:07 am

Re: Need help how to create mass data in database

Post by Gunner »

damn man ur a genius!!!!!!!!!!!!!!!!!!! you gave me the idea now :D
thanks!!
Skype: mrvictordiaz
User avatar
Sharlenwar
Posts: 524
Joined: Mon May 28, 2012 7:14 pm

Re: Need help how to create mass data in database

Post 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.
Deep within the Void of Quasion, a creation.

**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
tourmaline
Posts: 34
Joined: Thu Mar 20, 2014 9:43 pm

Re: Need help how to create mass data in database

Post 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.
User avatar
Sharlenwar
Posts: 524
Joined: Mon May 28, 2012 7:14 pm

Re: Need help how to create mass data in database

Post 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
Deep within the Void of Quasion, a creation.

**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
Post Reply

Return to “Beginner Help and Support”