How does the ajax product filtering function determine the final position of this post from q5975166 to 2014-07-0719: 49: 42 Edit: I saved the options for filtering items to a field in the database in json format (cp_leibie). For example, I saved three options: {208: [209], 5: [182], 6: [30], 27: how to determine the ajax product screening function
This post was last edited by q5975166 on 19:49:42
I saved the options for filtering items to a field (cp_leibie) in the database in json format)
For example, I saved three
Their options are
{"208": ["209"], "5": ["182"], "6": ["30"], "27 ": ["36"], "28": ["34"]} if the data id is 1
{"92": ["201", "202", "204"], "93": ["137", "138", "139"], "94": ["143", "144"]} if the data id is 2
{"208": ["209"], "5": ["182"], "6": ["29"], "27 ": ["35"], "28": ["33"]} assume that the data id is 3
Traverse by array when retrieving
-----------------------------------------------------------------
For example, one of the items is (applicable environment: all office modern European)
Then $ peistr is the id of the "applicable environment", and $ liestr is the id of the suboptions next to it,
I will not post any details about how to receive them,
In the for loop below, there is no need to consider why we subtract two.
The following are the query statements submitted by ajax:
$ Strpei = "select 'id', 'name', 'huiyuanjia ', 'cpim', 'shichangjia', cp_leibie from '". $ db_prefix. "chanpin 'where' ifxianshi '= 1 and 'cpfl' = '". $ sid. "'";
$ Dqcp = $ Db-> FetchAll ($ strpei); // This is the method for executing SQL statements.
$ Strpei. = "and id in (";
$ Strpei2 = "";
Foreach ($ dqcp as $ dkey => $ dvalue) {// traverse all items
$ Darr = json_decode (urldecode ($ dvalue ['CP _ leibie ']), true); // decodes json data
For ($ I = 0; $ I
Foreach ($ darr [$ peistr [$ I] as $ dddkey => $ dddvalue) {// traverses decoded data, the key name is the id of the received item option
If ($ liestr [$ I] ==$ dddvalue) {// if the sub-option id is the same as the value in the json data, add the data id to the condition.
$ Strpei2. = $ dvalue ['id']. ",";
}
}
}
}
$ Strpei. = $ strpei2 .")";
If the conditions are met, the corresponding item id is written into the in syntax of the conditions.
If you click a subitem of 209, the IDS with IDs 1 and 3 will be added to the condition.
The problem is that it is okay to receive the data for the first time. when you click 201 for the second time, there should be no matching data, but the data of the three IDs is displayed.
It should be the if statement in the loop that is not written correctly. I don't know how to write the condition. Or you can solve it elsewhere.
------ Solution --------------------
I changed my judgment.
if($liestr[$i]==$dddvalue){
$strpei2.=$dvalue['id'].",";
}
$where.="$liestr[$i]==$dddvalue &&";
if($i==(count($peistr)-2)){
$where= substr($where,0,-2);
}
if($where){
$strpei2.=$dvalue['id'].",";
}
But in this case, $ where is a string to be placed in if for determination. No judgment can be performed. no matter what $ where is, it is 1. This is just an idea. let's take a look.