node.js - node-mysql - return rows where column contains string -


i want create function returns objects db string contained in 1 of object's columns.

this code:

router.get('/search-news', function (req, res) {    var input = req.query.title; // user input   var dynamicinput = '%'.concat(title.concat('%'));    connection.query('select * news title = ?', [dynamicinput], function (err, rows) {     console.log(err);     res.json(rows);   }); }); 

html:

<form action="search-news" class="form-inline right search-form" method="get">    <input type="text" name="title" class="form-control" placeholder="Поиск..."></input>    <input type="submit" class="btn btn-success" value="Поиск"></input> </form> 

however, function returns 0 records db. problem?

thank you

your dynamic input seems appending percent signs beginning , end of string.

 var dynamicinput = '%'.concat(title.concat('%')); 

it highly unlikely strings have format, suspect want like:

 connection.query('select * news title ?', [dynamicinput], function (err, rows) { 

however, not familiar nodejs, there may other problems well.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -