首页 > 代码库 > 表格的循环插入

表格的循环插入

例子1

include ‘./connect.php‘;

for ($i = 1; $i <= 1000; $i++) {
$sql = ‘INSERT INTO cs_category ‘;
$sql .= ‘(category, parentid, createtime) ‘;
$sql .= ‘VALUES ("分类‘ . $i . ‘", "0", "‘.$_SERVER[‘REQUEST_TIME‘].‘");‘;
// echo $sql.‘<BR>‘;

$rs = mysql_query($sql);
if ($rs) {

} else {
echo mysql_error();
}
}

 

例子2

$goodname = ‘尼龙双肩包女韩版新款百搭潮牛津‘;
// 产生20个商品价格
$prices = array();

for ($i = 1; $i <= 20; $i ++) {
$prices[] = rand(5000, 10000) / 100;
}
// echo ‘<pre>‘;
// print_r($prices);
for ($i = 0; $i < 100; $i ++) {
$cateid = rand(1, 20);
$sql = "INSERT INTO cs_goods (cateid, goodname, price, markamout, quantity, createtime)";
$sql .= " VALUES (‘" . $cateid . "‘, ‘" . $goodname . "‘, ‘" . $prices[$cateid - 1] . "‘, ‘" . $prices[$cateid - 1] * 1.2 . "‘, ‘" . rand(10, 50) . "‘, ‘" . rand(1485878400, 1492498567) . "‘);";
$rs = mysql_query($sql);
if ($rs) {

} else {
echo mysql_error();
}
}

表格的循环插入