我该怎么做才能从多个表中获取数据?
var express = require('express');
var app = express();
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '',
user : '',
password : '',
database : ''
});
connection.connect(function(){
console.log("MySQL Database is Connected");
});
app.use(express.static(__dirname + '/css'));
app.use(express.static(__dirname + '/js'));
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.get('/',function(req,res){
res.render('index.html');
});
app.get('/load',function(req,res){
connection.query("select * from terms WHERE status = 1",
function(err,rows,fields){
if(err) throw err;
res.end(JSON.stringify(rows));
});
});
app.listen(7001,function(){
console.log("App is started at PORT 7001");
});
js / app.js
var app = angular.module('terms', []);
js / core.js
app.controller('main_control',function($scope,$http){
load_terms();
function load_terms(){
$http.get("http://localhost:7001/load").success(function(data){
$scope.loaded_terms=data;
})
}
});
MySQL表架构
terms
表
| ID | termTitle | termStatus |
|------|--------------|----------------|
| 1 | hello | 1 |
| 2 | world | 1 |
impTerms
表
| ID | impTermsTitle | termStatus |
|-------|-----------------|----------------|
| 1 | winter | 1 |
| 2 | is coming | 1 |
角度; HTML视图:
<td>{{yaz.termTitle}}</td> // for table: "terms"
terms
表中获取数据。但是我需要从impTerms
表中获取数据。
我怎么得到的?
谢谢