我试图运行此代码,但我遇到了错误。 有什么想法吗?
ON
答案 0 :(得分:1)
由于你只能有一个var http = require('http');
var path = require('path');
var socketio = require('socket.io');
var express = require('express');
var router = express();
var server = http.createServer(router);
var io = socketio.listen(server);
router.use(express.static(path.resolve(__dirname, 'public')));
var clients = [];
io.on('connection', function (socket) {
console.log("ID: "+socket.id.substring(2)+"has connected");
clients[socket.id] = {
vote:''
};
io.sockets.emit('count', socket.client.conn.server.clientsCount);
socket.on('vote', function(data){
clients[socket.id].vote = data; // good or bad
var result = calcVote(clients);
io.sockets.emit('vote', result);
});
socket.on('disconnect', function() {
delete clients[socket.id];
io.sockets.emit('count', socket.client.conn.server.clientsCount);
});
});
var calcVote = function(calcclients){
var sums = {
good:0,
bad:0
};
calcclients.forEach(function(client){
switch (client.vote) {
case 'good' :
sums.good += 1;
break;
case 'bad' :
sums.bad += 1;
break;
}
});
return sums;
};
server.listen(process.env.PORT || 3010, process.env.IP || "0.0.0.0", function(){
var addr = server.address();
console.log("Chat server listening at", addr.address + ":" + addr.port);
});
node.js socket.io
子句,你可以使用这样的内连接:
WHERE
答案 1 :(得分:0)
应该有单WHERE
条款。
SELECT notes.project_id, notes.title, notes.description
FROM notes, project_members
WHERE
(notes.title LIKE '%second%' OR notes.description LIKE '%second%')
AND notes.project_id = project_members.project_id AND project_members.user_id = '7';
查询会在您的 LIKE 条件之间看到 AND 。
您也可以考虑使用JOIN
,像这样。
SELECT notes.project_id, notes.title, notes.description
FROM notes
JOIN project_members
ON notes.project_id=project_members.project_id
WHERE
(notes.title LIKE '%second%' OR notes.description LIKE '%second%')
AND project_members.user_id = '7';
答案 2 :(得分:0)
您有两个WHERE
子句,但单SELECT
只允许一个。但是,如果您使用正确的,明确的JOIN
语法,这将轻松修复:
SELECT n.project_id, n.title, n.description
FROM notes n JOIN
project_members p
ON n.project_id = p.project_id
WHERE (n.title LIKE '%second%' OR n.description LIKE '%second%') AND
p.user_id = '7';
注意:
JOIN
语法。 从不在FROM
子句中使用逗号。WHERE
条件缺少括号,符合您的预期逻辑。user_id
是任意类型的数字,则不要在“7”周围使用单引号。这可能会使编译器和人员感到困惑。