Insert range of values into mysql database using php [closed]

假装没事ソ 提交于 2021-02-05 11:32:05

问题


I need to insert range of values into my database table. User will select a range .... e.g:20 to 100 ... So the numbers ranging from 20 to 100 must be added into the table in separate rows....How can i implement this using php script


回答1:


$startIndex = 20;
$endIndex = 100;

while($startIndex<=$endIndex)
{
$query = $pdo->prepare("Insert into table (field1)";
$query += " values (?)";
$query-> bindValue(1,$startIndex);
$startIndex++;
$query->execute();
}



回答2:


<?php
  // Dummy values
  $startCount = 45;
  $endCount = 100;
  while ($startCount <= $endCount) {
    $resultInsert = mysql_query("INSERT into tableName (columnName1,columnName2)".
                                " values ('$value1', '$value2')");
    $startCount++;
  }
?>


来源:https://stackoverflow.com/questions/22047527/insert-range-of-values-into-mysql-database-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!