Wednesday, 19 April 2017

SQL statement with conditionals

I'm currently building a food application which has users select a range of options (perishable, non-perishable ) and (snack, produce or meal) via a set of radio buttons. I'm currently using node.js and sqlite 3 to query a database to determine which entries to return to the user after they search the database.

I want to write a query such that when the booleans from the client-side are sent over to the server, the server will choose the entries such that perishable if perishable is set to true on the client that the query will find just the perishable items and vice-versa. I also want the same functionality with

Example:

perishable = request.perishable.
non-perishable = request.non-perishable
snack = request.non-perishable
meal = request.non-perishable
produce = request.non-perishable.

var q = 'SELECT * FROM posts WHERE available == true AND (if perishable is true all rows where the perishable column is set to true... etc );



via learner561

No comments:

Post a Comment