-1
I am trying to display a data taken directly from my database with this script:
<script>
setInterval( function contaUser(){
document.write,("<?php
$sql = "SELECT Count(id) as c FROM tb_usuario";
$result = $con->query($sql);
$row = $result->fetch_assoc();
echo $row['c'].' Usuários';
?>");
},2000 );
</script>
Already includes at the beginning of the file all the connection data and etc... I would like to display this data in a div, "card" style... You could tell me what’s wrong?
Have you heard of server-side and client-side languages? For example, PHP will act on the server side, while Javascript, in this case, will act on the client side. The single how they communicate is by HTTP. Search about it, as it seems that you still lack some concepts basic and necessary.
– Woss
Friend, you will not be able to run a php code within a javscript scope. What you can do is send an ajax with the data pro php server, do the query, and export the data back to javascript. Then you do the setInterval and update x in x times.
– Máttheus Spoo
Follow this: https://aiocollective.com/blog/auto-refresh-content-after-changes-in-database-ajax/
– Lollipop
All right, thank you very much!
– Erick Figueiredo
div
estilo "card"...
how so?– user60252
Welcome Erick Figueiredo, don’t miss these posts to get good answers https://answall.com/help/mcve
– user60252
A good practice is to accept an answer that may have solved your problem. See how in https://i.stack.Imgur.com/evLUR.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252