Is it possible to have a WHERE clause after imploding array? I need to insert only rows where priority >=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);
答案 0 :(得分:2)
Insert statements shouldn't have a where
clause. Instead use PHP to filter what goes into the $array
variable. 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);
?>