Home:ALL Converter>Assign variables to query mysql on NodeJS

Assign variables to query mysql on NodeJS

Ask Time:2017-05-01T21:24:43         Author:Moomoo Soso

Json Formatter

Hi I have some problem on nodejs to get data on mysql

My question is 'How can I add var n into "%drawing eye%" to get data on database?'

  function showResult(req, res){
                var n = req.query.query
                mysql_conn.query('SELECT query_text FROM catalogsearch_query WHERE query_text LIKE "%drawing eye%" ORDER BY popularity DESC LIMIT 0 , 10', function(error, rows){
                res.render('result.html',{result:n , related: rows.map(row => row.query_text)})
                })
        }

Author:Moomoo Soso,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43719822/assign-variables-to-query-mysql-on-nodejs
Sachila Ranawaka :

do something like this LIKE \"%' + n + '%\" ORDER BY\n\nfunction showResult(req, res) {\n var n = req.query.query\n mysql_conn.query('SELECT query_text FROM catalogsearch_query WHERE query_text LIKE \"%' + n + '%\" ORDER BY popularity DESC LIMIT 0 , 10', function(error, rows) {\n res.render('result.html', {\n result: n,\n related: rows.map(row => row.query_text)\n })\n })\n}\n",
2017-05-01T13:27:12
yy