Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.route('/people')
  2.     .get(function(req, res) {
  3.         connection.query('SELECT * FROM people', function(error, results, fields) {
  4.             if (error)
  5.                 res.json({
  6.                     status: 500,
  7.                     error: error
  8.                 });
  9.             rows = JSON.parse(JSON.stringify(results));
  10.             for (i = 0; i < rows.length; i++) {
  11.                 if (rows[i].name.indexOf("person") !== -1) {
  12.                     person = rows[i];
  13.                     name = rows[i].name.split('_');
  14.                     name2 = name[1].split('-');
  15.                     final = "picture_" + name2[0];
  16.                     connection.query("SELECT * FROM `picture` WHERE `name` = ?", [final], function(error, results, fields) {
  17.                         if (error)
  18.                             res.json({
  19.                                 status: 500,
  20.                                 error: error
  21.                             });
  22.                         row = JSON.parse(JSON.stringify(results))[0];
  23.                         person.picture = row.name;
  24.                         array.push(person);
  25.                     });
  26.                 } else {
  27.                     array.push(rows[i]);
  28.                 }
  29.             }
  30.             res.json({
  31.                 status: 200,
  32.                 people: array
  33.             });
  34.         });
  35.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement