Note that there are some explanatory texts on larger screens.

plurals
  1. PORefining the search results based on the filters
    primarykey
    data
    text
    <p>I am working on an e-commerce website. While displaying the available mobiles, user can filter the results by the following filters:</p> <ol> <li><p><strong>Brand name</strong></p> <ul> <li>Samsung</li> <li>Nokia</li> <li>HTC</li> <li>(and many more)</li> </ul></li> <li><p><strong>Price range</strong></p> <ul> <li>$100-$200</li> <li>$200-$300</li> <li>(and so on)</li> </ul></li> <li><p><strong>Category</strong></p> <ul> <li>Android Mobiles</li> <li>Low cost mobiles</li> <li>Music Phones</li> <li>3G Phones</li> <li>...(and many more)</li> </ul></li> </ol> <p>I want to use the following GET parameters to generate a sql query which will execute everytime a filter is applied. Suppose the current filter is <code>Brand=Samsung</code> then my link will be <a href="http://xyz.com/mobiles.php?brand=samsung" rel="nofollow">http://xyz.com/mobiles.php?brand=samsung</a></p> <p>For the above filters, PHP code for generating the SQL query is as follows (using lots of <code>if/else</code> statements and <code>isset()</code> function):</p> <pre><code>$sql = "SELECT * from items "; if(isset($_GET['brand'])) { $sql = $sql . "where brand=".$_GET['brand']." "; /*similar statements*/ } </code></pre> <p>Please don't go on the accuracy of the above PHP statements, I have not mentioned the full code. Finally I have the following SQL generated which will provide the result:</p> <pre><code>SELECT * FROM ITEMS WHERE BRAND=SAMSUNG; </code></pre> <p>This SQL query will result the matching products and I will display the results on webpage accordingly. Please answer the following questions:</p> <ol> <li><p>After the above filters (brand), suppose price filter is also applied. How can I know that <code>brand</code> filter is already there so that I can redirect the user to</p> <p><a href="http://xyz.com/mobiles.php?brand=samsung&amp;priceMin=100&amp;priceMax=200" rel="nofollow">http://xyz.com/mobiles.php?brand=samsung&amp;priceMin=100&amp;priceMax=200</a></p> <p><strong>INSTEAD OF THE FOLLOWING URL</strong></p> <p><a href="http://xyz.com/mobiles.php?priceMin=100&amp;priceMax=200" rel="nofollow">http://xyz.com/mobiles.php?priceMin=100&amp;priceMax=200</a></p> <p>i.e. how can i just append the price criteria to the url? </p></li> <li><p>Is there any software/library/code available to filter the products?</p></li> <li><p>Is there any better way to filter out products or any better way to generate the SQL than the method I mentioned above?</p></li> </ol> <p>I am using PHP, MySQL, Apache on Windows machine.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload