Adrie Posted February 12, 2013 Share Posted February 12, 2013 (edited) I really don't know how to start. The goal is to make a form where a user can give some options and at the and of the form there will be a listing of products to choose. I really have searched al lot at google but don't know how such a form is called. My table in Mysql is like this. Brand: x Fax: y/n Copy: y/n A4: y/n A3: y/n A3+: y/n I really hope someone can give me some help. Edited February 12, 2013 by Adrie Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 12, 2013 Share Posted February 12, 2013 I really have searched al lot at google but don't know how such a form is called. I think what you're looking to build is a questionnaire. Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 12, 2013 Share Posted February 12, 2013 Fax: y/n Copy: y/n A4: y/n A3: y/n A3+: y/n Are these the questions you plan on asking to the user? And then displaying the brands matching the users answers? Quote Link to comment Share on other sites More sharing options...
Adrie Posted February 12, 2013 Author Share Posted February 12, 2013 (edited) Are these the questions you plan on asking to the user? And then displaying the brands matching the users answers? Every product does have a brand name like OKI and does haven or not have functions, like fax.When a user select Brand OKI and does need fax then alle products with brandname OKI and Fax: Y will be listed. And yes that are some questions i want to ask. Edited February 12, 2013 by Adrie Quote Link to comment Share on other sites More sharing options...
Adrie Posted February 12, 2013 Author Share Posted February 12, 2013 I think what you're looking to build is a questionnaire. Thank you. Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 12, 2013 Share Posted February 12, 2013 Ok, so you are filtering products. This isn't really a questionnaire, then. Are you looking for help building the HTML markup for the form, or query to display the products depending on what the user has selected? Quote Link to comment Share on other sites More sharing options...
Adrie Posted February 12, 2013 Author Share Posted February 12, 2013 Ok, so you are filtering products. This isn't really a questionnaire, then. Are you looking for help building the HTML markup for the form, or query to display the products depending on what the user has selected? I need help to query to display the products. Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 12, 2013 Share Posted February 12, 2013 (edited) You would do something like: $sql = "SELECT * FROM products WHERE 1=1 "; // Dynamically build the rest of the query, depending on what the user has selected in the form - example if($_GET['fax'] == 'y') { $sql .= "AND fax = 'y'"; } if($_GET['copy'] == 'y') { $sql .= "AND copy='y'" } //Etc... The 1=1 part is a trick/hack, so you don't have to keep track of your first AND in the query. You could keep track of this manually if you want, though. It's up to you, there's many ways to do it. But the key is, you'll be building the query dynamically depending on the user input. Hope this helps. Edit: This is assuming you're using checkboxes on the form. If you require them to answer every question, then you don't need a dynamically built query. Edited February 12, 2013 by shlumph Quote Link to comment Share on other sites More sharing options...
Adrie Posted February 12, 2013 Author Share Posted February 12, 2013 You would do something like: $sql = "SELECT * FROM products WHERE 1=1 "; // Dynamically build the rest of the query, depending on what the user has selected in the form - example if($_GET['fax'] == 'y') { $sql .= "AND fax = 'y'"; } if($_GET['copy'] == 'y') { $sql .= "AND copy='y'" } //Etc... The 1=1 part is a trick/hack, so you don't have to keep track of your first AND in the query. You could keep track of this manually if you want, though. It's up to you, there's many ways to do it. But the key is, you'll be building the query dynamically depending on the user input. Hope this helps. I will give it a try. Thank you for your time to answer my question. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.