PDA

View Full Version : possible? mixing javascript with php



crobinson42
05-23-2010, 05:35 PM
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?


<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...


<?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)';
}

?>

crobinson42
05-23-2010, 05:36 PM
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

djr33
05-23-2010, 09:34 PM
Reloading the page is reloading the PHP. That should be fine.