Php 为预定义的数字运行while循环(以执行查询)

Php 为预定义的数字运行while循环(以执行查询),php,mysql,for-loop,Php,Mysql,For Loop,我想运行此查询10次: $query = mysqli_query($connect, "INSERT INTO user_thoughts VALUES ('','message', '$date_of_msg','', '$name', 'yes')"); 根据我的理解,需要一个for循环吗?但我不明白该查询如何适合while循环,例如,到目前为止,我已经知道了: for($i=0; $i < 10; $i++) { $query = mysqli_query($connec

我想运行此查询
10次

$query = mysqli_query($connect, "INSERT INTO user_thoughts VALUES ('','message', '$date_of_msg','', '$name', 'yes')");
根据我的理解,需要一个for循环吗?但我不明白该查询如何适合while循环,例如,到目前为止,我已经知道了:

for($i=0; $i < 10; $i++) {
    $query = mysqli_query($connect, "INSERT INTO user_thoughts VALUES ('','message', '$date_of_msg','', '$name', 'yes')");
        break;
}
($i=0;$i<10;$i++)的
{
$query=mysqli_query($connect,“在用户思想值中插入(“”,'message','date_of_msg','','$name','yes');
打破
}
但是上面为我生成了28个新行,而我希望查询执行10次。

为什么包含“break”?我想这是你的问题。在第一次执行结束时,“中断”将使程序脱离该循环。去掉“break”,代码将执行10次。

$i=1;
$i = 1;
while($i <= 10) {
    $query = mysqli_query($connect, "INSERT INTO user_thoughts VALUES ('','message', '$date_of_msg','', '$name', 'yes')");
 $i++;
}

虽然($i),但很明显,上面的查询将只执行一次,而不是10次,也不是28次。因此答案似乎是“您正在循环中运行此查询”.for
循环的
在技术上不是必需的。这取决于您是否需要在查询中动态使用
$i
值。至于'while'循环,请参阅下面的答案。我不知道该代码为您生成28行的神奇之处!