How the Ajax product screening function is judged

Source: Internet
Author: User
I put the various options for filtering items into a field in the database as JSON (Cp_leibie)
For example, I saved 3 records.
Their option is to
{"208": ["209"], "5": ["182"], "6": ["30"], "27": ["36"], "28": ["34"]} if the data ID of the bar is 1
{"92": ["201", "202", "204"], "93": ["137", "138", "139"], "94": ["143", "144"]} if the data ID of the bar is 2
{"208": ["209"], "5": ["182"], "6": ["29"], "27": ["35"], "28": ["33"]} if the data ID of the bar is 3
Loop through the array when it is removed
-----------------------------------------------------------------
For example, one of the options in the product is (applicable environment: all Office Modern European)
Then $PEISTR is the "applicable environment" ID, $LIESTR is the ID of the subsequent sub-option,
Specifically how to receive it is not posted out,
Why minus two in the following for loop is not considered.
The following is the AJAX submission of past query statements:
$strpei = "Select ' id ', ' name ', ' Huiyuanjia ', ' cpimg ', ' Shichangjia ', Cp_leibie  from  '". $db _prefix. " Chanpin ' where ' Ifxianshi ' =1 and ' cpfl ' = ' ". $sid." ' "; $DQCP = $Db->fetchall ($strpei);//This is the method that executes the SQL statement $strpei.=" and ID in ("; $strpei 2=" "; foreach ($dqcp as $dkey =>$ Dvalue) {//Traverse all goods $darr=json_decode (UrlDecode ($dvalue [' Cp_leibie ']), true);//decode JSON data for ($i =0; $i
 
  
   
  $dddvalue) {//The decoded data is traversed, the key name is the idif of the Received commodity option ($liestr [$i]== $dddvalue) {//Sub-option ID and the value of the JSON data is consistent, the ID of the data is added to the condition $ strpei2.= $dvalue [' id ']. ",";}}} $strpei. = $strpei 2. ")";
 
  

The ID of the corresponding product is written into the in grammar of the condition according to the condition.
If you click on a subkey of 209, then IDs 1 and 3 will be added to the condition
The problem is that the first time you receive a second time when you click 201, there should be no qualifying data, but the data for the 3 IDs is displayed.
Should be in the loop if the judgment is not written right, do not know the conditions to write. Or somewhere else to work it out.


Reply to discussion (solution)

$peistr This can be printed out to see?

$peistr This can be printed out to see?


If you select a subkey of 209
Print the results of a $peistr
Array (
[0] = 208
[1] = =
[2] = =
[3] = =
[4] = =
[5] = =
[6] = =
)
Print the results of a $liestr
Array (
[0] = 209
[1] = =
[2] = =
[3] = =
[4] = =
[5] = =
[6] = =
)
After you select a subkey of 209, select the child of 30
Print the results of a $peistr
Array (
[0] = 208
[1] = =
[2] = 6
[3] = =
[4] = =
[5] = =
[6] = =
)
Print the results of a $liestr
Array (
[0] = 209
[1] = =
[2] = 30
[3] = =
[4] = =
[5] = =
[6] = =
)
The last two in the array, that is, the key name is 5,6, is useless, that is why in the For loop minus 2. In fact, there are only 5 options in the product selection, the following molecular items.

If I choose to do this, the criteria should be the only ID 3.
The condition I wrote above
if ($liestr [$i]== $dddvalue) {/
$strpei 2.= $dvalue [' id ']. ",";
}
is to put all the conditions in the line.
That is, 208 of the Children, ID 1 also have, ID 3 also have. All he did was look up the data for these two IDs.

$peistr This can be printed out to see?



And the last sentence was, "so he checked out all two IDs."

Strange positioning data organization, strange query construction method

Strange positioning data organization, strange query construction method


This is also a way of thinking. Each column has a different number of options, you can not build each one field

I think of the idea that the $PEISTR array receives the first time, only one index has a value. When the second time is received, there are two indexes with values. Then you can judge the value of the first time you receive it. When you receive the second time, you will be judged at the same time two values. And so on But I haven't figured out exactly how to write it.

Another idea is that when receiving the first time, the ID of the eligible product will be added to the condition. When receiving the second time, if there is in the original ID, it is added. Then add the ID to the condition.

I changed my judgment a bit.



$where. = "$liestr [$i]== $dddvalue &&", if ($i = = (count ($peistr)-2)) {$where = substr ($where, 0,-2);} if ($where) {$strpei 2.= $dvalue [' id ']. ",";}

But in this case, $where he is a string to be judged in the IF. No judgment can be processed no matter what $where is 1. It's just a thought, you see.

I changed my judgment a bit.



$where. = "$liestr [$i]== $dddvalue &&", if ($i = = (count ($peistr)-2)) {$where = substr ($where, 0,-2);} if ($where) {$strpei 2.= $dvalue [' id ']. ",";}

But in this case, $where he is a string to be judged in the IF. No judgment can be processed no matter what $where is 1. It's just a thought, you see.


Yes, because he is connected as a string, the If judgment string result is 1. I'm afraid this method won't work.

I thought of a method, the ID of the item into a field, with Find_in_set to query, after each query with and Find_in_set, the received subkey ID in the field query, so OK.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.