简体   繁体   English

MySQL WHERE 子句

[英]MySQL WHERE clause

Is it possible to have a WHERE clause after imploding array?内爆数组后是否可以有 WHERE 子句? I need to insert only rows where priority >=1.我只需要插入优先级 >=1 的行。 Thanks.谢谢。

$array = array(); 
foreach ($priority as $priority) 
$array[] = "('$id', '$studentname', '$title', '$academicdiscipline', '$priority')";

$query = "INSERT INTO flux_project_selection (id, studentname, title,
academicdiscipline, priority)  VALUES ". implode(',', $array);

Insert statements shouldn't have a where clause. Insert 语句不应包含where子句。 Instead use PHP to filter what goes into the $array variable.而是使用 PHP 来过滤进入$array变量的内容。 Here's an example:下面是一个例子:

<?php

$array = array(); 
foreach ($priority as $priority) {
    if ($priority >=1) {
        $array[] = "('$id', '$studentname', '$title', '$academicdiscipline', '$priority')"; 
    }
}

$query = "INSERT INTO flux_project_selection (id, studentname, title,
academicdiscipline, priority)  VALUES ". implode(',', $array);

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM