Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.route('/people')
- .get(function(req, res) {
- var array = [];
- connection.query('SELECT * FROM people', function(error, results, fields) {
- if (error)
- res.json({
- status: 500,
- error: error
- });
- var rows = JSON.parse(JSON.stringify(results));
- for (i = 0; i < rows.length; i++) {
- if (rows[i].name.indexOf("person") !== -1) {
- var person = rows[i];
- var name = rows[i].name.split('_');
- var name2 = name[1].split('-');
- var final = "picture_" + name2[0];
- connection.query("SELECT * FROM `picture` WHERE `name` = ?", [final], function(error, results, fields) {
- if (error)
- res.json({
- status: 500,
- error: error
- });
- var row = JSON.parse(JSON.stringify(results))[0];
- person.picture = row.name;
- array.push(person);
- });
- } else {
- array.push(rows[i]);
- }
- }
- res.json({
- status: 200,
- people: array
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement