Some simple and basic code for internet users has been given below to purchase for products using keywords. These are variables that retrieve the user value sent by the user, which is used to parse the XML document below.
$ name = $ _GET ["name_keywords"]; $ Value = $ _GET ["price_keyword"]; $ Store = $ _GET ["store_keywords"];
Internet user is not required to submit a search query and send value to all the three variables - IE can / he only search by price, name and price etc.). Therefore, some variables used to parse XML document below can be zero. Then the "if statement" given below in the foreach
loop will have to keep the account.
If the statement given below is a problem, because it does not work. If the statement has any advice about coding, then it can parse the XML document for matching criteria on one, two or three conditions and keep in mind that some variables can be redundant? Thanks!
& lt ;? Php $ xmlDoc = simplexml_load_file ("products.xml"); Foreign currency ($ xmlDoc-> as the product $ product) {if (($ name == $ product- & gt; name) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; ampull amp; & Amp; amp; amp; amp; $ Product-> Price == $ Price) & amp; amp; ($ Store) & amp; $ Product-> Store == $ Store)) {Resonance "Name : "$ Product-> Name ","; Echo "value:" $ product-> value ","; Echo "value:" $ product-> Store ","; }}
Here is the XML file:
& lt; Products & gt; & Lt; Product Type = "Electronics" & gt; & Lt; Name & gt; Desktop & lt; / Name & gt; & Lt; Price & gt; 499.99 & lt; / Pricing & gt; & Lt; Store & gt; Best Buy & lt; / Store & gt; & Lt; / Products & gt; & Lt; Product Type = "Electronics" & gt; & Lt; Name & gt; Coating top & lt; / Name & gt; & Lt; Price & gt; 599.99 & lt; / Pricing & gt; & Lt; Store & gt; Best Buy & lt; / Store & gt; & Lt; / Products & gt; & Lt; Product Type = "Hardware" & gt; & Lt; Name & gt; Hand saw & lt; / Name & gt; & Lt; Price & gt; 99.99 & lt; / Pricing & gt; & Lt; Shop & gt; Lowes & lt; / Shop & gt; & Lt; / Products & gt; & Lt; / Products & gt;
You should check the three conditions
Then your position if ((empty ($ name) || $ product-> name = name $ name) and amp; amp; amp; und ($ value) || $ Product- & gt; value == $ value) & amp; (Empty ($ store) || $ product- & gt; store == $ store) {{code>
Comments
Post a Comment