I am working on a NodeJS/MySQL application.
There is a dropdown and each option have a value which is being sent as a criteria into a MySQL query for rows of the same table.
I need to have an "All" option (for salesperson) which will not abstract results based on this selection and it will function like ignoring the specific criteria in the MySQL query so or alternatively work as a wildcard for it which makes more sense.
However I can't figure out how to pass or not to pass at all this criteria for when I have the "All salespersons" selected (no value).
Function which passes the form's selected options as values into MySQL query
var field = req.body.mode;
var start_date = req.body.start_date;
var end_date = req.body.end_date;
var operator = req.body.operator;
var paid_operator = req.body.paid_operator;
var user_id = user.id;
var salesperson = req.body.salesperson;
db.select_between_dates_office( table, field, start_date, end_date, user_id,
salesperson, function(data) { // do something
});
MySQL query
this.select_between_dates_office = function( table, field, start_date, end_date, user_id, salesperson, callback ){
var query_string = "select * from "+ table +" where "+ field +" between '"+ start_date +"'
and '"+ end_date + "' and user_id='" + user_id +"' and salesperson='" + salesperson + "'";
connection.query( query_string, function(err,rows){
// do some stuff
})
}
via Vasilis Kosmas
No comments:
Post a Comment