我正在网站上制作一些过滤器,我必须按会话过滤某些数据的属性。我的例子是通过过滤属性和id,我不知道如何选择属性和他的属性的所有id。属性的代码和我尝试做的是这样的:
if (isset($_REQUEST['Filtru']) && strpos($_REQUEST['Filtru'], 'atr') === 0) {
if (isset($_REQUEST['AtributID']) && (int) $_REQUEST['AtributID'] > 0) {
$_SESSION['Catalog']['Filtre']['Atribute']['AtributID'] = $_REQUEST['AtributID'];
$_SESSION['Catalog']['Filtre']['Atribute']['Filtru'] = $_REQUEST['Filtru'];
$_SESSION['offset'] = 0;
}
else {
unset($_SESSION['Catalog']['Filtre']['Atribute'][$_REQUEST['Filtru']][-1 * (int) $_REQUEST['AtributID']]);
}
}
这就是我尝试的方式:
if (isset($_REQUEST['Filtru']) && strpos($_REQUEST['Filtru'], 'atr') === 0) {
if (isset($_REQUEST['AtributID']) && (int) $_REQUEST['AtributID'] > 0) {
$_SESSION['Catalog']['Filtre']['Atribute']['AtributID'] = $_REQUEST['AtributID'];
$_SESSION['Catalog']['Filtre']['Atribute']['Filtru'] = $_REQUEST['Filtru'];
$_SESSION['offset'] = 0;
}
else if (!isset($_REQUEST['AtributID']) || (int) $_REQUEST['AtributID'] <= 0) {
if (isset($_REQUEST['Atribute']) && (int) $_REQUEST['Atribute'] > 0) {
$_SESSION['Catalog']['Filtre']['Atribute'] = $_REQUEST['Atribute'];
$_SESSION['Catalog']['Filtre']['Filtru'] = $_REQUEST['Filtru'];
$_SESSION['offset'] = 0;
}
else {
unset($_SESSION['Catalog']['Filtre']['Atribute'][$_REQUEST['Filtru']]);
}
}
else {
unset($_SESSION['Catalog']['Filtre']['Atribute'][$_REQUEST['Filtru']][-1 * (int) $_REQUEST['AtributID']]);
}
}
在另一个函数中应用过滤器的newt步骤如下所示:
$fstr = '';
if(isset($_SESSION['Catalog']['Filtre']['Atribute']['AtributID']) && isset($_SESSION['Catalog']['Filtre']['Atribute']['Filtru']))
$fstr .= ' '.$_SESSION['Catalog']['Filtre']['Atribute']['Filtru'].' in ('.$_SESSION['Catalog']['Filtre']['Atribute']['AtributID'].')';
像我这样,但是它给了我内爆函数的错误,而且Atribut是未定义的:
if (isset($_SESSION['Catalog']['Filtre']['Atribute']) && count($_SESSION['Catalog']['Filtre']['Atribute'])) {
foreach ($_SESSION['Catalog']['Filtre']['Atribute'] as $k => $v) {
if (count($v)) {
if (strlen($fstr))
$fstr .= ' AND ';
$vals = '(' . implode(',', $v) . ')';
$fstr .= " $k in $vals ";
}
}
有人可以帮助我吗?
答案 0 :(得分:0)
我不确定你要做什么,但在我看来,内爆应该把一个数组作为第二个参数;)
试试这个
if (isset($_SESSION['Catalog']['Filtre']['Atribute']) && count($_SESSION['Catalog']['Filtre']['Atribute'])) {
if (count($_SESSION['Catalog']['Filtre']['Atribute'])) {
if (strlen($fstr))
$fstr .= ' AND ';
$vals = '(' . implode(',', $_SESSION['Catalog']['Filtre']['Atribute']) . ')';
}
这样你就可以在$ _SESSION ['目录'] ['Filtre'] ['Atribute']中包含一系列Atributes。你不需要使用foreach。