Javascript Set Interval

hi all :) i whant to call a function that return the number of notification in my database so i made this function

it working but i need to refrech the page i don’t know why it didn’t chage automaticly


            function() {

                setInterval(function() {

                   // var randomnumber = Math.floor(Math.random() * 100);



             $var = Yii::app()->db->createCommand('select * from notification where  etat = "non lu"  and id_user ='.Yii::app()->user->id)->query();

             $count = count ( $var);


                 var span = document.getElementById("show");

               span.textContent = <?php echo $count; ?>  ;


                }, 1000);

            })  ;

can someone help me please :) thx

That can’t work. The PHP code is executed once on the initial page load. You can’t execute server side code on the client in the way you’re attempting.

You need to use ajax to call an action which returns the relevant data.

hos can i do that ?? thx

Are you find that problem?