简体   繁体   English

每次在PHP中插入1000行

[英]Insert 1000 rows in php each time different

We have this code: 我们有以下代码:

for($i=1;$i=1000;$i++){
  mysql_query("INSERT INTO testing VALUES ('".$i."')");
  //do some other testing
}

It enters the same value 1000 times but what I need is that every time (from this 1000 times) to insert a different value. 它输入相同的值1000次,但我需要的是每次(从此1000次起)插入不同的值。

For example: 例如:

$n = rand(1,300);
$n2 = $n/2;
mysql_query("INSERT INTO testing VALUES ('".$i."')");

So do this action for 1000 times and each time to do it again. 因此,请执行此操作1000次,然后每次再次执行此操作。 Not to insert the same data from first result it is possible? 不可以从第一个结果中插入相同的数据吗?

The original loop is nearly correct, with the exception of the 2nd statement. 除了第二条语句外,原始循环几乎是正确的。 It should be a comparison, instead you are setting. 它应该是一个比较,而不是您正在设置。

Correct version for($i=1;$i<=1000;$i++){ . for($i=1;$i<=1000;$i++){正确版本。 Notice the $i <= 1000; 注意$i <= 1000; instead of $i = 1000; 而不是$i = 1000; .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM