gpt4 book ai didi

php - 增量停止在 10

转载 作者:搜寻专家 更新时间:2023-10-30 20:40:27 25 4
gpt4 key购买 nike

我正在尝试通过将每个重复值递增 1 来递增 csv 文件中插入到 mysql 数据库的值。因此,如果我将“processor-intel”插入到我的数据库中,如果 csv 中的值存在,则该值将递增 1。这将导致“processor-intel1”等。例如,如果我在我的 csv 中有 13 次“nvidia-graphic-card”但具有不同的规范,增量从 1 到 10,结果将是:

'nvidia-graphic-card',
'nvidia-graphic-card1',
'nvidia-graphic-card2',
'nvidia-graphic-card3',
........
'nvidia-graphic-card9',
'nvidia-graphic-card10',
'nvidia-graphic-card10',
'nvidia-graphic-card10'

为什么递增在 10 处停止?

这是我使用的增量函数:

  function increment_string($str, $separator = '-', $first = 1){
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);

return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;

我正在将 csv 中的每一行与数据库进行比较

$verificare = $database->select("SELECT alias FROM produse WHERE alias LIKE '%".$alias."%'");

for($x=0;$x<$database->countRows();$x++){
if($alias == $verificare['alias'][$x]){
$alias = $this->increment_string($verificare['alias'][$x], '-', 1);
}else{
$alias = $alias;
}
}

这是导入csv的完整代码

    if($request->get($_POST["action"]) == "import"){

$file = $upload->file_upload("import", "media/import");
if(file_exists(DIR_UPLOAD_PHOTO . "/media/import/" . $file)){

$file = DIR_UPLOAD_PHOTO . "/media/import/" . $file;
$handle = fopen($file, "r");

if ($handle) {
$lines = explode("\r", fread($handle, filesize($file)));
}

$total_array = count($array);

$x = 0;

foreach($lines as $line){

if($x >= 1){
$data = explode("|", $line);

$titlu = trim(addslashes($data[0]));
$alias = $this->generate_seo_link($titlu);
$gramaj = trim($data[1]);
$greutate = trim($data[2]);
$pret_total = trim($data[3]);
$pret_redus = trim($data[4]);
$poza = trim($data[5]);
$pret_unitar = trim($data[6]);
$categorie = trim($data[7]);
$brand = trim(addslashes($data[8]));
$descriere = trim(addslashes($data[9]));
$vizibil = trim($data[10]);
$cod = trim($data[11]);
$nou = trim($data[12]);
$cant_variabila = trim($data[13]);
$congelat = trim($data[14]);
$tva = trim($data[15]);
$stoc = trim($data[16]);


if($cod != "" && $cod != " "){

$verificare = $database->select("SELECT alias FROM produse WHERE alias LIKE '%".$alias."%'");

for($x=0;$x<$database->countRows();$x++){
if($alias == $verificare['alias'][$x]){
$alias = $this->increment_string($verificare['alias'][$x]);
}else{
//$alias = $alias;
}
}




$database->insert(sprintf("insert into produse set
titlu='%s',
alias='%s',
gramaj='%s',
greutate='%s',
prettotal='%s',
pretredus='%s',
poza='%s',
pretunitar='%s',
categorie='%d',
brand='%s',
descriere='%s',
vizibil='%d',
cod='%s',
nou='%d',
cant_variabila='%d',
congelat = '%d',
tva = '%s',
stoc = '%d'

on duplicate key update

titlu='%s',
gramaj='%s',
greutate='%s',
prettotal='%s',
pretredus='%s',
poza='%s',
pretunitar='%s',
categorie='%d',
brand='%s',
descriere='%s',
vizibil='%d',
cod='%s',
nou='%d',
cant_variabila='%d',
congelat = '%d',
tva='%s',
stoc= '%d'",

$titlu, $alias,
$gramaj, $greutate, $pret_total, $pret_redus, $poza, $pret_unitar, $categorie,
$brand, $descriere, $vizibil, $cod, $nou, $cant_variabila, $congelat,
$tva, $stoc,

$titlu, $gramaj, $greutate,
$pret_total, $pret_redus, $poza, $pret_unitar, $categorie, $brand, $descriere,
$vizibil, $cod, $nou, $cant_variabila, $congelat, $tva, $stoc));


}
}
$x++;
}



}
}

最佳答案

如果您的别名列类型设置为 varchar ..将其更改为文本。

SQLite Query Stops Incrementing at 10

关于php - 增量停止在 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22687874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com