嘿,我是NodeJS的新手,我想知道..如何获取像PHP这样的mysql查询
var express = require('express');
var router = express.Router();
var db = require('../database');
/* GET users page. */
router.get('/' , function(req, res, next) {
db.query('SELECT * FROM accounts', function(err, rows) {
// Fields > Return Table Fields ( Name , type , length .... )
// rows > return Rows Data
db.query("select * from comments where user = ?",
[rows[0].Username],
function(err, rowx) {
console.log('User Comments : '+rowx);
console.log('Usernames : '+rows.Username);
});
if (err) throw err;
numRows = rows.length;
res.render('users', {
title: 'Users Table',
rowCount: numRows,
rowsData: rows
});
}); // END OF Query
});
module.exports = router;
还有一件事
iam使用ExpressJS和我的users.js
self.contentArray = [NSMutableArray array];
NSArray *array = json[@"posts"];
[self.contentArray addObjectsFromArray: array];
NSLog(@"%ld",(long)self.contentArray.count);
如何使用帐户表中的用户名获取评论表中的数据?
答案 0 :(得分:0)
你应该使用异步包来使用像php这样的nodejs你在nodejs中的第一个代码块可以是这样的:
var async=require('async');
async.auto(
{
getAccounts:function(cb,results){
db.query('SELECT * FROM accounts', function(err, rows) {
cb(null,rows)
})
},
showRows:['getAccounts',function(cb,results){
var accounts=results.getAccounts;
for(var account in accounts){
console.log(accounts[accont])
}
}]
},
function(err,allResult)
{
}
)