mysql - Express query for SQL -
i dynamically trying pass name of table sql query in part of express code below
background information::
- what passing (key,value) string name of table in sql database
- why doing dynamically select table based on dynamic client request
problem facing::
- clearly not sunig sql query correctly
- how solve this
[expresscode]
app.get('/restaurantdesc/:key',function(request,response,next){ var keyname=request.params.key; var name_of_restaurants, restauranttimings; async.series( [ // first table contents function ( callback ) { connection.query('select * keyname', function(err, rows, fields) { console.log('connection result error '+err); name_of_restaurants = rows; callback(); }); }, // second table contents function ( callback ) { connection.query('select * restauranttimings', function(err, rows, fields) { console.log('connection result error '+err); restauranttimings = rows; callback(); }); } // send response ], function ( error, results ) { response.json({ 'restaurants' : name_of_restaurants, 'restauranttimings' : restauranttimings }); } ); } );
considering keyname
, restauranttimings
table name. try this:-
app.get('/restaurantdesc/:key',function(request,response,next){ var keyname=request.params.key; var name_of_restaurants, restauranttimings; async.series( [ // first table contents function ( callback ) { connection.query('select * ', keyname, function(err, rows, fields) { console.log('connection result error '+err); name_of_restaurants = rows; callback(); }); }, // second table contents function ( callback ) { connection.query('select * ', restauranttimings, function(err, rows, fields) { console.log('connection result error '+err); restauranttimings = rows; callback(); }); } // send response ], function ( error, results ) { response.json({ 'restaurants' : name_of_restaurants, 'restauranttimings' : restauranttimings }); } ); } );
Comments
Post a Comment