Pedro Alves

Members
  • Content Count

    3
  • Joined

  • Last visited

Everything posted by Pedro Alves

  1. i using nodejs ,mysql ,express i trying put two methods in same route to render the same file but i have this error in my firefox 404 my code aliança route const express = require('express') const router = express.Router() const connection = require('../../Config/database') const controllerAdmin = require('../../controllers/Administration') const controlleruser = require('../../controllers/Alliances') router.get('/Administration/Alliances', (req, res) => controllerAdmin.findcidade3(connection, req, res)); router.get('/Administration/Alliances', (req, res) => controlleruser.findAlianca(connection, req, res)); module.exports = app => app.use('/', router) aliança controller const Allianca = require('../models/Alliances') const findAlianca = async (connection, req, res) => { const allianca = await Allianca.find(connection,req.session.user.username) if (!allianca) { res.status(404).send('Nenhuma cidade encontrada.') return; } console.log("dddd"); req.session.alianca = allianca res.locals.alianca = allianca res.render('Administration/Alliances') } module.exports = { findAlianca } aliança models const find = (connection,username) => { return new Promise((resolve, reject) => { connection.query(`SELECT alianca.nome,alianca.N_membros,alianca.TAG FROM user INNER JOIN alianca ON user.cod_alianca=alianca.id WHERE user.username='${username}'`, (err, result) => { if(err){ reject(err) }else{ console.log(result[0]); resolve(result[0]) } }) }) } module.exports = { find } na app tenho o seguinte require('./routes/Administration/Alliances')(app) aliança.jade tenho assim extends layout block title .col-xs-6.col-xs-offset-3.col-sm-6.col-sm-offset-3 .col-sm-4(style='width:76%') div.panel.panel-primary(style='height:50px') Alliances Page div.panel.panel-primary(style='height:700px') fdssdklfsdklfjskldfjkldsjfl if locals.user.cod_alianca==null p You Dont Have Alliances else br span Your Aliance span= locals.alianca.nome .col-xs-2.panel-red(style='width:24%;height:100%;text-align:center') coneção com base dados tenho o seguinte const mysql = require('mysql') const config = require( "./config.json" ) const connection =mysql.createConnection({ host:config.host, user:config.user, password:config.password, database:config.database, // port:config.port }); connection.connect((err) =>{ if(err){ console.log(err) process.exit(0) }else{ console.log('database on') } }) connection.query(`CREATE TABLE IF NOT EXISTS user (userId INT(11) NOT NULL AUTO_INCREMENT, username VARCHAR(50) DEFAULT NULL, password VARCHAR(60) DEFAULT NULL, PRIMARY KEY (userId))`, (err ,result) =>{ if(err){ console.log(err) } }) module.exports = connection and cmd have this errors GET /Administration/Alliances 500 217.138 ms - 7876 GET /Administration/vendor/bootstrap/css/bootstrap.min.css 404 42.201 ms - 7876 GET /Administration/vendor/fontawesome/css/font-awesome.min.css 404 80.007 ms - 7876 GET /Administration/vendor/themify-icons/themify-icons.min.css 404 112.356 ms - 7876 GET /Administration/vendor/animate.css/animate.min.css 404 142.545 ms - 7876 GET /Administration/vendor/perfect-scrollbar/perfect-scrollbar.min.css 404 176.203 ms - 7876 GET /Administration/vendor/switchery/switchery.min.css 404 208.608 ms - 7876 GET /Administration/stylesheets/plugins.css 404 35.953 ms - 7876 GET /Administration/stylesheets/styles.css 404 64.049 ms - 7876 what i doing wrong
  2. I'm not getting by code to work The result should be 125 150 175 And this always gives this 125 125 125 125 how i solve the problem Follow the code server.php <?php require_once ('configurations/config.php'); // arquivo cujo conteúdo será enviado ao cliente //$dataFileName = 'data.txt'; $timestart=time(); $PDO = new PDO('mysql:host=localhost;dbname=game', 'root',''); if(isset($_POST ['timestamp'])){ $timestamp=$_POST [ 'timestamp' ]; } else { $tempo=$PDO->prepare("SELECT NOW() as now"); $tempo->execute(); $row=$tempo->fetchObject(); $timestamp=$row->now; } $sql = $PDO->prepare("SELECT cidade.ouro,cidade.madeira,cidade.metal,cidade.pedra,cidade.energia, cidade.comida,cidade.petrolio FROM users INNER JOIN cidade ON users.cod_user=cidade.cod_user WHERE cidade.timestamp>'$timestamp'AND users.username='admin';"); $newdata = false; $notificacoes=array(); while (!$newdata &&(time()-$timestart)<20) { $sql->execute(); while ($row=$sql->fetchAll(PDO::FETCH_ASSOC)) { $notificacoes=$row; $newdata=true; } usleep(500000); } $tempo=$PDO->prepare("SELECT NOW() as now"); $tempo->execute(); $row=$tempo->fetchObject(); $timestamp=$row->now; $data= array('notificacoes'=>$notificacoes,'timestamp'=>$timestamp); echo json_encode($data); exit(); ?> client.js $(function(){ notificacoes(); }); function notificacoes(timestamp){ var data={}; var resultado=0; var soma=2; var valor=25; if(typeof timestamp!='undefined') data.timestamp=timestamp; $.post('server.php',data,function(res){ for(i in res.notificacoes ){ resultado=+res.notificacoes[i].ouro+valor; $('#response').append(resultado); } notificacoes(res.timestamp); },'json'); } ola.php <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script type="text/javascript" src="dist/js/client.js"></script> </head> <body> <h3>Conteúdo</h3> <div id="response" name="response"></div> </body> </html>