<?php
for ($r = 1, $r <= 100, $r++) {
for ($c = 1, $c <= 100, $c++) {
$query = "INSERT INTO locations (loc_name,loc_desc,loc_event,loc_x,loc_y,tile_id) VALUES ('Ocean','Lots of water.','0','$r','$c','50')";
}
}
?>
I'm not sure at all if this will work :3 Basically the idea is to input values for all columns of row 1 first, then row 2, row 3, ..., row 100. Double check to make sure $c is reset to 1 after each 'r' loops.
EDIT - If the arrays begin with 0, which I'm sure they do, of course set $r and $c to 0 and the conditional integer to <= 99.
Elegance is refined through practice. If you're stuck with a problem that deals with tons of repetition, always figure out how to do one run of the iteration through psuedo code first, then the next, then the next 10, then everything all together. You're essentially simplifying the problem to its most fundamentals, then using a common rule to apply to a scaled up version of the problem.
There are a bunch of code snippets all over the internet that solve common problems in unique ways: I suggest joining a PHP or programming message board if you're looking to get into it further. People always seem willing to help even the simplest programming questions.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Problem: I'm trying to write a script that inserts in x and y values automatically so that I don't have to do each one manually:
I'm very bad at math. How would you advise going about this?
I'm not sure at all if this will work :3 Basically the idea is to input values for all columns of row 1 first, then row 2, row 3, ..., row 100. Double check to make sure $c is reset to 1 after each 'r' loops.
EDIT - If the arrays begin with 0, which I'm sure they do, of course set $r and $c to 0 and the conditional integer to <= 99.
There are a bunch of code snippets all over the internet that solve common problems in unique ways: I suggest joining a PHP or programming message board if you're looking to get into it further. People always seem willing to help even the simplest programming questions.