tiko165 Posted February 18, 2016 at 06:34 PM Report Share #593655 Posted February 18, 2016 at 06:34 PM Necessito de realizar uma contagem de uma query, e pretendia que fosse executado em Ajax ou Javascript. Nesta query vou seleccionar o id do user e o dia atual, como por exemplo: SELECT * FROM table1 WHERE id='x' AND date='2016-02-18' A ideia, é quando um utilizador carrega num botão, é enviado dados para a BD (já funcional), mas pretendia colocar uma limitação diária de 10 linhas. Caso o user pretendesse realizar a 11º linha, não iria ser possivel, dando um aviso! Mas como faço para ler a query em Ajax ou JS? Link to comment Share on other sites More sharing options...
KTachyon Posted February 18, 2016 at 06:37 PM Report Share #593656 Posted February 18, 2016 at 06:37 PM Tens que ter alguma coisa no servidor que faça a chamada à base de dados. Por ajax chamas o endpoint que faz essa chamada e te devolve o resultado. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
tiko165 Posted February 18, 2016 at 07:00 PM Author Report Share #593659 Posted February 18, 2016 at 07:00 PM A leitura ao servidor eu tenho facilmente... A minha ideia, é fazer continuação deste botão (Que tenho a funcionar) https://www.portugal-a-programar.pt/topic/70879-comandos-sql-atraves-de-ajaxjquery/?do=findComment?comment=583267 Mas pretendo agora colocar uma limitação de envios à BD... Neste momento, a minha dificuldade é mesmo como devolver o resultado, para a mensagem. Link to comment Share on other sites More sharing options...
KTachyon Posted February 19, 2016 at 03:14 AM Report Share #593672 Posted February 19, 2016 at 03:14 AM Mas para limitares a 10 linhas por utilizador tens que registar isso na base de dados. Se, para o dia actual já existirem mais de 10 registos devolves um código de erro que tratas depois no javascript. Tens que ter em atenção que a verificação por acessos diários varia com a timezone. Se utilizares a timezone do teu servidor podes ter um problema com os utilizadores que estão noutras timezones (se estiveres a contabilizar 10 pedidos num dia fixo). Podes optar por 10 acessos nas últimas 24h e resolves esse problema. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
tiko165 Posted February 19, 2016 at 12:49 PM Author Report Share #593678 Posted February 19, 2016 at 12:49 PM @KTachyon, o que me disses-te, eu tenho perfeita noção que isso poderá acontecer. Mas o meu problema é como conseguir passar isso para JS... Tens algum exemplo de codigo para que me possas ajudar? Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted February 19, 2016 at 01:41 PM Report Share #593682 Posted February 19, 2016 at 01:41 PM usar a informação temporal em javascript ? https://developer.mozilla.org/en-US/docs/Web/Javascript/Reference/Global_Objects/Date IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now