Adrie Posted February 12, 2013 Share Posted February 12, 2013 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. Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/ 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. Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412019 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? Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412020 Share on other sites More sharing options...
Adrie Posted February 12, 2013 Author Share Posted February 12, 2013 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. Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412022 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. Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412024 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? Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412025 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. Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412027 Share on other sites More sharing options...
shlumph Posted February 12, 2013 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. 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. Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412033 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. Link to comment https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/#findComment-1412035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.