Forum Moderators: coopster

Message Too Old, No Replies

Creating a "Configuration tool"

         

Joppiesaus

1:12 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



Hello,

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]

coopster

5:01 pm on Oct 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi Joppiesaus, welcome to WebmasterWorld.

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).

cameraman

5:03 pm on Oct 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have a look in this forum's library [webmasterworld.com], in particular:
Developing MySQL search query [webmasterworld.com]
and possibly
Basics of extracting data from MySQL [webmasterworld.com]

Joppiesaus

12:18 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



So what I basicaly need to do is create a "get" for every WHERE statement. So when a get is added to the URL the Query gets the value and updates the output?

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]

coopster

1:06 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Your first statement here sounds like you have the basic concept, yes. Now you just need to learn how to structure your query. Most often folks will use the POST method in their forms rather than a GET method. However, let's use a simple GET request by using a URL as an example. Your link would look something like ...
<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>

... and when a user clicks that link, your productfetch.php script would handle the request.
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
}

Something along those lines anyway ...

Joppiesaus

8:04 pm on Oct 28, 2008 (gmt 0)

10+ Year Member



So this script enables me to pass multiple variables in the URL to which all products in the database have to match? The URL looks like it will be used to show a product/detail page.

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!

coopster

2:25 pm on Oct 29, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The script was merely an example that further demonstrates the information provided in the links by cameraman. Your php processing page is the page that will be accepting your GET variables and refining the search and then displaying the output. That page will extract the variables you expect to receive, edit check them for validity, escape them for proper/safe use in a query, and execute the query. It will then process the result set and format the output for display in a browser. The key to all this is how you manipulate the query, most significantly the WHERE clause which is going to reduce the product result set.