dsbiw2911188 2016-06-02 20:08
浏览 54

通过while循环插入多行

I'm trying to make a grid/map based on coordinates, and instead of inputting a million rows manually I'm trying to figure out a way to do it in just a few queries but I'm having trouble wrapping my mind around how to do it.

What I want it to do is enter a row for each coordinate to create a 1000x1000 square with each square in the grid being a row I just need some help figuring out how to actually put this in a query.

I ran this code twice one time each with the while loop +1 each time for $onecoord and then once with it adding +1 to $twocoord I knew it wouldn't fully fill out the table it only added 999 coordinates each time.

$onecoord = 1;
$twocoord = 1;


while($twocoord < 1000) {
    mysqli_query($link,"INSERT INTO coords (x, y, walkable, image, spawn) 
                         VALUES('".$onecoord."','".$twocoord."','1','grass2.png','0')") 
or die($link->error); 

    $twocoord = $twocoord + 1;
}

Any help would be very much appreciated, thanks in advance.

.
.
.
.
.
.
.
.
. . . . . . . . . . .

That is what the coords I'm getting look like I want to make it so it is a full square + completely filled in with each dot ='s a row in the database.

  • 写回答

1条回答 默认 最新

  • doumi7854 2016-06-02 20:50
    关注

    I figured it out, this is the solution.

    $onecoord = 1;
    $twocoord = 1;
    
    while($twocoord <= 1000){
    mysqli_query($link,"INSERT INTO coords
    (x, y, walkable, image, spawn) VALUES('".$onecoord."','".$twocoord."','1','grass2.png','0')") 
    or die($link->error); 
    
    $twocoord = $twocoord + 1;
    
    if($twocoord == 1000 && $onecoord <= 1000){
    $twocoord = 1;  
    $onecoord = $onecoord + 1;  
    
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题