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.

Link to comment
https://forums.phpfreaks.com/topic/274406-question-form-to-give-advise/
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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.