【发布时间】:2015-04-10 10:38:44
【问题描述】:
2 月编辑。 2015年11月11日-11:38
我花了几个小时寻找正确的解决方案,但没有实现我的目标。我只想在我的 WHERE IN 请求中读取我的 multiselect[] 和 checkboxes[] 的选定值。 我已经尝试了几个小时不同的解决方案,但我仍然完全陷入困境。
感谢您的帮助
$secteur_searched="";
if (!empty($_REQUEST['secteur_searched']) AND is_array($_REQUEST['secteur_searched']))
{ foreach ($_REQUEST["secteur_searched"] as $selectedOption)
$secteur_searched.=$selectedOption.",";
}
if ($secteur_searched)
{ $secteur_searched = rtrim($secteur_searched, ',');
$where[] = "j.job_secteur IN (:job_secteur) " ;
$param[':job_secteur']= $secteur_searched;
var_dump($secteur_searched); // returns (1,2,3)
}
if (!empty($where))
{ $query.= ' WHERE ' . implode(' AND ', $where);
}
$query.= " ORDER BY j.job_date_insertion DESC";
$sth =$marInterim ->prepare($query);
$sth->execute($param);
$compte = $sth->fetchAll();
$nb_resultats = count($compte);
$errors['nb_resultats_recherche'] = $nb_resultats; // ok (for ajax)
/********************/
if ( !empty($_REQUEST['afficher_x_resultats']))
{ $per_page=$_REQUEST['afficher_x_resultats'];
}
else {$per_page=10; }
/* Results per page */
$nb_pages = ceil($nb_resultats/$per_page);
$current_page = isset($_REQUEST['page']) && ($_REQUEST['page'] > 0) && ($_REQUEST['page'] <= $nb_pages) ? $_REQUEST['page'] : 1;
$start = ($current_page-1)*$per_page;
$query2= $query." LIMIT $start,$per_page ";
$sth2 =$marInterim ->prepare($query2);
$sth2-> execute($param);
//print_r($sth2->errorInfo());
while($datos= $sth2->fetch(PDO::FETCH_ASSOC))
{ $en_date_insertion=$datos['job_date_insertion'];
$explode_insertion= explode("-", $en_date_insertion);
$date_insertion_fr = $explode_insertion[2]."-".$explode_insertion[1]."-".$explode_insertion[0];
$job_id= $datos['job_id'];
$job_intitule= strtoupper($datos['job_intitule']);
$job_ville = $datos['ville_nom'];
$job_cp = $datos['cp'];
echo 'hello';
echo "
<div class='offers btns'>
<a class='link_vers_offre' href='job_offer_detail.php?job_id=$job_id'>
<table id='table_liste_des_offres'>
<tr>
<td class='liste_intitule'> " .$job_intitule." </td>
<td class='liste_ref'>Offre n°" .$job_id." du ".$date_insertion_fr ." </td>
<td class='liste_ville'> ".$job_cp. " ".$job_ville." </td>
</tr>
</table>
</a>
</div>
";
}
【问题讨论】:
-
函数参数(一旦更正)返回:
SELECT * FROM marinterim_job_offers j JOIN marimmo_villes v ON v.ville_id =j.job_ville WHERE j.job_secteur IN ('1,2,3,4,5,6,13') ORDER BY j.job_date_insertion DESC LIMIT 0,10 -
我发现了,并且明白数组中包含的所有值都必须被引用,但我不知道如何将下面的代码与我的匹配。
$idlist = array('260','201','221','216','217','169','210','212','213'); $questionmarks = str_repeat("?,", count($idlist)-1) . "?"; $stmt = $dbh->prepare("DELETE FROMfoo` WHEREidIN ($questionmarks)");`