Jump to content

Question form to give advise


Adrie

Recommended Posts

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 by Adrie
Link to comment
Share on other sites

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 by Adrie
Link to comment
Share on other sites

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
Share on other sites

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 by shlumph
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.