Web Hosting Talk







View Full Version : Need help with while


AniMud
09-06-2009, 10:47 AM
I'm wondering if someone can help me....

What i'm trying to do is basically have a script output a great deal of numbers.... based on co-ordinates... like x y z


This is what i want it to output:

x: -150 to +150
y: -150 to +150
z: -150 to +150

But seeing as this will be placed inside a database, for every "x" there has to be a "y". and as i'm trying to make a perfect square, it would have to be like....


INSERT INTO 'map' (
`x` ,
`y` ,
`z` ,
)
VALUES (
'-150', '-150', '1'
);


so before x goed to -149, y would need to have already gone through the whole -150 to +150 thing...


i hope you can understand lol

bigfan
09-06-2009, 11:07 AM
If I understand it correctly, it's just a matter of looping the loops:for ($x = -150; $x <= 150; $x++) {
for ($y = -150; $y <= 150; $y++) {
for ($z = -150; $z <= 150; $z++) {
db_insert("INSERT INTO map (x, y, z) VALUES($x, $y, $z)";
}
}
}Of course, the inserting might be done more efficiently, but the triplets could be generated this way. I haven't done the math to see what the total size of the results would be, since I assume you have and know it would be very large. Edit: 27270901 triplets.

AniMud
09-06-2009, 11:21 AM
@bigfan:
Thats perfect!

Basically the map will display only the x and y co-ords based on the what "z" co-ord you are on.