Forum Moderators: coopster
I'm quite new at php, butwhat I want to do is something like this:
Narrow down the list of products by selecting variables that apply to you. What would be the best way to do this? I guess they are doing it with some kind of infinate GET method, because for every selection it just keeps adding get variables to the URL. I just have no clue as to how this works.
I hope you guyz can help.
Kind regards.
[edited by: coopster at 2:23 pm (utc) on Oct. 24, 2008]
[edit reason] removed url [/edit]
You could add get variables to the url by using JavaScript and/or PHP. JavaScript won't be as reliable as users may have it turned off or just flat out not allow it to run in their browser. Using PHP, you grab the submitted form values and use them to narrow down the selection(s).
When I use this code:
SELECT *
FROM product
WHERE merk = %colname% AND prijs = %colname2%
Colname:
name: Colname
type: text
Default value: -1
Runtime value: $_Get['merk']
name: Colname
type: text
Default value: -1
Runtime value: $_Get['prijs']
Is this the right way to go at it? It nowoutputs nothing, even when I fill in the variables in the URL
E.g: .php?prijs=100
[edited by: Joppiesaus at 12:21 pm (utc) on Oct. 27, 2008]
<a href="http://www.example.com/productfetch.php?prijs=productA">Product A</a>
<a href="http://www.example.com/productfetch.php?prijs=productB">Product B</a>
<a href="http://www.example.com/productfetch.php?prijs=productC">Product C</a>
if (isset [php.net]($_GET['prijs']) && trim($_GET['prijs'])) {
$prijs = trim($_GET['prijs'];
// Make it safe for a query:
$prijs = mysql_real_escape_string [php.net]($prijs);
$sql = "SELECT * FROM product WHERE prijs = '$prijs'";
// ... execute query and process result set
} else {
// no product requested, handle accordingly
}
WHat I really want to do is let people select a few variables to make a long list of products shorter to help them pick a product that suits them...
For instance let them say the product can be not more then 150$ AND is of Brand "X" AND has the color Green. Is this something this script can do? I already have a get function on my product.php page which gets the product information via a GET. What I want to do now is show less products on the same page by updating with the variables chosen....
Hope you guyz can help (maybe I just misunderstood the script above?)
Thanks!