# Thread: Need help with while

1. Newbie
Join Date
Apr 2009
Posts
11

## Need help with while

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

Join Date
Nov 2005
Posts
123
If I understand it correctly, it's just a matter of looping the loops:
PHP Code:
``` 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.
Last edited by bigfan; 09-06-2009 at 11:19 AM.

3. Newbie
Join Date
Apr 2009
Posts
11
@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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•