Results 1 to 3 of 3

Thread: possible? mixing javascript with php

  1. #1
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default possible? mixing javascript with php

    disclaimer: I don't know js.. yet. i am very close to completing a project and came across a bump where i could use some help.


    I have this js function to reload, and i would like to perform a database query every time it reloads to check for new messages... is this possible?

    Code:
    <script type="text/javascript">
    
    setTimeout(function(){
      location.href.reload(true);
    }, 50000);
    
    </script>
    Everytime the js reload's i want to run this on the server...

    Code:
    <?php
    $query = "SELECT * FROM mail_box WHERE receiver_id='$user_id'";
    $result = mysqli_query($dbc, $query);
    while($row = mysqli_fetch_array($result)){
    if($row['message_read'] == '0'){
    	
    	echo 'New message(s)';
       }
         
    ?>

  2. #2
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    i realize js is client side, and php is server side. But there has gotta be a way for js to do a http refresh or something..right?

    Thanks,
    Cory

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Reloading the page is reloading the PHP. That should be fine.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •