Keywoords filter
Ik wil een een filter gaan bouwen die gaat filteren op keywoords die ik zelf heb toegevenzen aan een product.
hier is de code die ik gebruik
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if ($_GET['filter'])
{
$ui = $_GET[filter];
$string = "";
$a = 1;
$b = count($ui);
echo $b;
foreach ($ui as $key => $value)
{
if(count($ui) == 1)
{
$string .= 'k.keyword_id = "' .$value. '"';
}
else
{
$uri = 'k.keyword_id';
if ($a == 1)
{
$string .= ' IN (' .$value. ', ';
$a++;
}
elseif ($a == $b)
{
$string .= $value. ')';
}
else
{
$string .= $value . ', ';
$a++;
}
}
}
if ($a != 1)
{
$string = $uri ." " .$string;
}
}
{
$ui = $_GET[filter];
$string = "";
$a = 1;
$b = count($ui);
echo $b;
foreach ($ui as $key => $value)
{
if(count($ui) == 1)
{
$string .= 'k.keyword_id = "' .$value. '"';
}
else
{
$uri = 'k.keyword_id';
if ($a == 1)
{
$string .= ' IN (' .$value. ', ';
$a++;
}
elseif ($a == $b)
{
$string .= $value. ')';
}
else
{
$string .= $value . ', ';
$a++;
}
}
}
if ($a != 1)
{
$string = $uri ." " .$string;
}
}
hij krijgt via de $_GET een nummer door dat bij dat id hoort
Het gaat allemaal goed zolang het maar filter is maar zijn het er meer dan heeft die er geen zin meer in
wat kan ik er doen
mvg
peter
Gewijzigd op 05/11/2010 10:00:31 door Smoke nvt
$ui = $_GET[filter]; daar ben je zowiezo nog quotes vergeten
Teun Hesseling op 05/11/2010 10:11:53:
$ui = $_GET[filter]; daar ben je zowiezo nog quotes vergeten
Ik heb ze er bij gezet maar krijg nog steeds het probleem
ik gebruik deze code om de producten uit te lezen
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
static function getList($siteID = 0, $languageID = 0, $frontEnd = false, $parentID = false, $currencyID = 0, $offset = 0, $count = 30, $orderBy = '', $orderDir = '', $where = '', $options='loadprices,loadoldprices,loadkeywords,loadproperties,loadsites,loadimages,loadaccessoires,loadsuggestions,loadtax,loadoptions')
{
$options = Product::parseOptions($options);
//print_r($where);
if (!checkInt($siteID) || !checkInt($languageID) || !checkBool($frontEnd) || !checkInt($currencyID) || !checkInt($count) || !checkInt($offset))
return false;
// $query = 'SELECT *, UNIX_TIMESTAMP(`dateadded`) as `dateadded`, UNIX_TIMESTAMP(`datemodified`) as `datemodified`, UNIX_TIMESTAMP(`dateexpected`) as `dateexpected`, UNIX_TIMESTAMP(`dateactive`) as `dateactive` FROM `'. TABLE_PREFIX .'product` WHERE 1';
$query = '
SELECT DISTINCT
p.*,
' . ((checkOption('loadprices', $options)) ? 'pp.price,' : ''). '
' . ((checkOption('loadoldprices', $options)) ? 'pop.oldprice,' : ''). '
UNIX_TIMESTAMP(p.`dateadded`) as `dateadded`,
UNIX_TIMESTAMP(p.`datemodified`) as `datemodified`,
UNIX_TIMESTAMP(p.`dateexpected`) as `dateexpected`,
UNIX_TIMESTAMP(p.`dateactive`) as `dateactive`
FROM
`'.TABLE_PREFIX.'product` `p`
';
if(checkOption('loadprices', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'productprice` `pp`
ON
p.id = pp.product_id AND pp.site_id = ' . $siteID . ' AND pp.currency_id = ' . $currencyID. '
';
}
if(checkOption('loadoldprices', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'productoldprice` `pop`
ON
p.id = pop.product_id AND pop.site_id = ' . $siteID . ' AND pop.currency_id = ' . $currencyID. '
';
}
if(checkOption('loadproperties', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'propertyvalue` `pprop`
ON
p.id = pprop.product_id
';
}
if(checkOption('loadoptions', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'optionvalue` `popt`
ON
p.id = popt.product_id
';
}
if(checkOption('loadkeywords', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'keywordlink` `k`
ON
p.id = k.link_id AND k.type = \'product\'
';
}
$query .= '
WHERE
(`p`.`site_id` = "'.SITE_ID.'" OR `p`.`omnipresent` = "1")
';
if (checkInt($parentID))
$query .= ' AND `p`.`category_id` = "'.$parentID.'"';
if ($frontEnd)
$query .= ' AND `p`.`active` = "1"';
if ($languageID)
$query .= ' AND `p`.`language_id` = "'.$languageID.'"';
if (checkString($where))
$query .= ' AND ('.$where . ')';
$query .= ' ORDER BY ';
if (checkString($orderBy))
{
$query .= '`'.$orderBy.'` ';
if (checkOrderDir($orderDir))
$query .= $orderDir;
$query .= ', ';
}
$query .= '`order` ASC';
if ($count > 0)
$query .= ' LIMIT '.$offset.', '.$count;
$db = new DB;
if (!$db->query($query) || $db->num_rows() == 0)
return array();
$list = array();
$product = false;
$previousID = false;
$order_array = array();
$order = 0;
while($row = $db->next_record())
{
$error = false;
$order ++;
if (empty($list[$row['id']]))
$list[$row['id']] = new Product($siteID, $row['id'], $languageID, $currencyID, $frontEnd, $row);
if (empty($order_array[$row['id']]))
$order_array[$row['id']] = $order;
if (checkOption('loadprices', $options) && !$list[$row['id']]->loadPrices())
$error = 2;
if (checkOption('loadoldprices', $options) && !$list[$row['id']]->loadOldPrices())
$error = 3;
if (checkOption('loadkeywords', $options) && !$list[$row['id']]->loadKeywords())
$error = 4;
if (checkOption('loadproperties', $options) && !$list[$row['id']]->loadProperties())
$error = 5;
if (checkOption('loadsites', $options) && !$list[$row['id']]->loadSites())
$error = 6;
if (checkOption('loadimages', $options) && !$list[$row['id']]->loadImages())
$error = 7;
if (checkOption('loadaccessoires', $options) && !$list[$row['id']]->loadAccessoires())
$error = 8;
if (checkOption('loadsuggestions', $options) && !$list[$row['id']]->loadSuggestions())
$error = 9;
if (checkOption('loadtax', $options) && !$list[$row['id']]->loadTax())
$error = 10;
if (checkOption('loadoptions', $options) && !$list[$row['id']]->loadOptions())
$error = 11;
if (!$list[$row['id']]->loadSubscriptionPrices())
$error = 12;
$list[$row['id']]->currentTitle = (isset($row['title']) ?urldecode($row['title']) :null);
$list[$row['id']]->currentDescription = (isset($row['description']) ?urldecode($row['description']) :null);
$list[$row['id']]->currentShortDescription = (isset($row['shortdescription']) ?urldecode($row['shortdescription']):null);
$list[$row['id']]->languages[$row['language_id']]['title'] = (isset($row['title']) ?urldecode($row['title']) :null);
$list[$row['id']]->languages[$row['language_id']]['description'] = (isset($row['description']) ?urldecode($row['description']) :null);
$list[$row['id']]->languages[$row['language_id']]['shortDescription'] = (isset($row['shortdescription']) ?urldecode($row['shortdescription']):null);
$list[$row['id']]->languages[$row['language_id']]['meta_description'] = (isset($row['meta_description']) ?urldecode($row['meta_description']) :null);
$list[$row['id']]->languages[$row['language_id']]['meta_keyword'] = (isset($row['meta_keyword']) ?urldecode($row['meta_keyword']) :null);
$list[$row['id']]->languages[$row['language_id']]['window_title'] = (isset($row['window_title']) ?urldecode($row['window_title']) :null);
$list[$row['id']]->languages[$row['language_id']]['url_rewrite'] = (isset($row['url_rewrite']) ?urldecode($row['url_rewrite']) :null);
}
$sorted_list = array();
foreach($order_array as $key => $order)
$sorted_list[$order] = $list[$key];
return $sorted_list; // Success (list with Product instances)
}
{
$options = Product::parseOptions($options);
//print_r($where);
if (!checkInt($siteID) || !checkInt($languageID) || !checkBool($frontEnd) || !checkInt($currencyID) || !checkInt($count) || !checkInt($offset))
return false;
// $query = 'SELECT *, UNIX_TIMESTAMP(`dateadded`) as `dateadded`, UNIX_TIMESTAMP(`datemodified`) as `datemodified`, UNIX_TIMESTAMP(`dateexpected`) as `dateexpected`, UNIX_TIMESTAMP(`dateactive`) as `dateactive` FROM `'. TABLE_PREFIX .'product` WHERE 1';
$query = '
SELECT DISTINCT
p.*,
' . ((checkOption('loadprices', $options)) ? 'pp.price,' : ''). '
' . ((checkOption('loadoldprices', $options)) ? 'pop.oldprice,' : ''). '
UNIX_TIMESTAMP(p.`dateadded`) as `dateadded`,
UNIX_TIMESTAMP(p.`datemodified`) as `datemodified`,
UNIX_TIMESTAMP(p.`dateexpected`) as `dateexpected`,
UNIX_TIMESTAMP(p.`dateactive`) as `dateactive`
FROM
`'.TABLE_PREFIX.'product` `p`
';
if(checkOption('loadprices', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'productprice` `pp`
ON
p.id = pp.product_id AND pp.site_id = ' . $siteID . ' AND pp.currency_id = ' . $currencyID. '
';
}
if(checkOption('loadoldprices', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'productoldprice` `pop`
ON
p.id = pop.product_id AND pop.site_id = ' . $siteID . ' AND pop.currency_id = ' . $currencyID. '
';
}
if(checkOption('loadproperties', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'propertyvalue` `pprop`
ON
p.id = pprop.product_id
';
}
if(checkOption('loadoptions', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'optionvalue` `popt`
ON
p.id = popt.product_id
';
}
if(checkOption('loadkeywords', $options)){
$query .= '
LEFT JOIN
`'.TABLE_PREFIX.'keywordlink` `k`
ON
p.id = k.link_id AND k.type = \'product\'
';
}
$query .= '
WHERE
(`p`.`site_id` = "'.SITE_ID.'" OR `p`.`omnipresent` = "1")
';
if (checkInt($parentID))
$query .= ' AND `p`.`category_id` = "'.$parentID.'"';
if ($frontEnd)
$query .= ' AND `p`.`active` = "1"';
if ($languageID)
$query .= ' AND `p`.`language_id` = "'.$languageID.'"';
if (checkString($where))
$query .= ' AND ('.$where . ')';
$query .= ' ORDER BY ';
if (checkString($orderBy))
{
$query .= '`'.$orderBy.'` ';
if (checkOrderDir($orderDir))
$query .= $orderDir;
$query .= ', ';
}
$query .= '`order` ASC';
if ($count > 0)
$query .= ' LIMIT '.$offset.', '.$count;
$db = new DB;
if (!$db->query($query) || $db->num_rows() == 0)
return array();
$list = array();
$product = false;
$previousID = false;
$order_array = array();
$order = 0;
while($row = $db->next_record())
{
$error = false;
$order ++;
if (empty($list[$row['id']]))
$list[$row['id']] = new Product($siteID, $row['id'], $languageID, $currencyID, $frontEnd, $row);
if (empty($order_array[$row['id']]))
$order_array[$row['id']] = $order;
if (checkOption('loadprices', $options) && !$list[$row['id']]->loadPrices())
$error = 2;
if (checkOption('loadoldprices', $options) && !$list[$row['id']]->loadOldPrices())
$error = 3;
if (checkOption('loadkeywords', $options) && !$list[$row['id']]->loadKeywords())
$error = 4;
if (checkOption('loadproperties', $options) && !$list[$row['id']]->loadProperties())
$error = 5;
if (checkOption('loadsites', $options) && !$list[$row['id']]->loadSites())
$error = 6;
if (checkOption('loadimages', $options) && !$list[$row['id']]->loadImages())
$error = 7;
if (checkOption('loadaccessoires', $options) && !$list[$row['id']]->loadAccessoires())
$error = 8;
if (checkOption('loadsuggestions', $options) && !$list[$row['id']]->loadSuggestions())
$error = 9;
if (checkOption('loadtax', $options) && !$list[$row['id']]->loadTax())
$error = 10;
if (checkOption('loadoptions', $options) && !$list[$row['id']]->loadOptions())
$error = 11;
if (!$list[$row['id']]->loadSubscriptionPrices())
$error = 12;
$list[$row['id']]->currentTitle = (isset($row['title']) ?urldecode($row['title']) :null);
$list[$row['id']]->currentDescription = (isset($row['description']) ?urldecode($row['description']) :null);
$list[$row['id']]->currentShortDescription = (isset($row['shortdescription']) ?urldecode($row['shortdescription']):null);
$list[$row['id']]->languages[$row['language_id']]['title'] = (isset($row['title']) ?urldecode($row['title']) :null);
$list[$row['id']]->languages[$row['language_id']]['description'] = (isset($row['description']) ?urldecode($row['description']) :null);
$list[$row['id']]->languages[$row['language_id']]['shortDescription'] = (isset($row['shortdescription']) ?urldecode($row['shortdescription']):null);
$list[$row['id']]->languages[$row['language_id']]['meta_description'] = (isset($row['meta_description']) ?urldecode($row['meta_description']) :null);
$list[$row['id']]->languages[$row['language_id']]['meta_keyword'] = (isset($row['meta_keyword']) ?urldecode($row['meta_keyword']) :null);
$list[$row['id']]->languages[$row['language_id']]['window_title'] = (isset($row['window_title']) ?urldecode($row['window_title']) :null);
$list[$row['id']]->languages[$row['language_id']]['url_rewrite'] = (isset($row['url_rewrite']) ?urldecode($row['url_rewrite']) :null);
}
$sorted_list = array();
foreach($order_array as $key => $order)
$sorted_list[$order] = $list[$key];
return $sorted_list; // Success (list with Product instances)
}
Ik denk dat daar je probleem zit. Wat stuur je door naar je GET bij meerdere id's?
Tevens kan ik je aanraden om duidelijke variabelen namen te kiezen en dus niet $a en $b daardoor raak je snel het overzicht kwijt.
je hebt ook boven in je script staan: $a=1; verderop heb je een if statement met daarin if($a==1) en een elseif en else maar die worden natuurlijk nooit bereikt omdat $a altijd 1 is in dit script.
succes
http://dc.iteeuwen.nl/page/980/products.html?filter[0]=1&filter[10]=11
die lees ik uit via het script (staat bovenaan) en geef die mee aan de query die word opgebouwd.
Zolang ik er maar 1 selecteerd gaat alles goed maar zijn het er meerdere dan laat die niks meer zien.
ik denk dat er iets iets niet goed staat in de query.