问题
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