jonhyhvaftn Posted January 12, 2016 at 11:48 AM Report Share #591865 Posted January 12, 2016 at 11:48 AM Bom dia pessoal, posso misturar Javascript com PHP, tipo isto: function getSub(clicked){ <?php $queryGetClicked = "SELECT * FROM products_sub WHERE mainCat = '".?>clicked<?php."'"; $resultGetClicked = $link->query($queryGetClicked); while($rowGetClicked = $resultGetClicked -> fetch_assoc()){ ?>alert(<?php echo $rowGetClicked['mainCat']; ?>);<?php } ?> } Ou seja, a minha questão é, dado que é uma função que só é ativada "onclick", o PHP só irá carregar quando a função for ativada ou carregará logo aquando a página carregue? É que não me está a funcionar o código. Obrigado! Link to comment Share on other sites More sharing options...
Solution KTachyon Posted January 12, 2016 at 12:37 PM Solution Report Share #591869 Posted January 12, 2016 at 12:37 PM O PHP é executado no servidor. O Javascript é executado no browser. O PHP já foi executado quando o Javascript for executar. Se queres fazer isto, crias um php isolado que faz a query e devolve os resultados. Depois no Javascript chamas o PHP e tratar os resultados. “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...
tuga74 Posted January 12, 2016 at 01:38 PM Report Share #591871 Posted January 12, 2016 at 01:38 PM O PHP corre antes da pagina "carregar" depois è enviada para o browser e depois funciona o Javascript. http://www.nova.news Nova aprende automaticamente o que gostas de ler e mostra os conteúdos que te interessam. 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