Jump to content

Refresh problem


RealDrift

Recommended Posts

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

<?php
session_start();
include "includes/db_connect.php";
include "includes/functions.php";
logincheck();
$username=$_SESSION['username'];
$viewuser=$_GET['viewuser'];
$check = mysql_query("SELECT `to`,`read` FROM `inbox` WHERE `read`='0' AND `to`='$username'");

echo '<pre>';
print_r(mysql_fetch_array($check));
echo '</pre>';

$inbox=mysql_num_rows($check);
if ($inbox > 0){ 
echo "<a href=inbox.php target=middle><img border=0 src=images/unread1.gif align=left  width=16 height=11></a> "; 
}else{ 
echo "<img src=images/read.gif align=left width=16 height=11>";
} 
?>

 

try that and see what happen after reading inbox and refreshing the page

Link to comment
Share on other sites

Sorry teng for replying late i had an exam to revise for. now thats over with.

 

I tried your script and the results are as follows:

 

- it echos the new message i recieve

- i have to manually refresh the page for the right image to appear and onc ei read the new message i have to refresh the page again and the picture changes to the appropriate one.

-only problem is ajax dsnt seem to change the pics.

 

 

hmm?

Link to comment
Share on other sites

you know what? i start over again:

 

i want to have an image on my website which changes to another pic when a user gets a new message and change back to the original pic once the user has read the message.

 

how can i refresh the info without page refresh, any unique ways to some how have a live connection with the server or something?

Link to comment
Share on other sites

Sorry teng for replying late i had an exam to revise for. now thats over with.

 

I tried your script and the results are as follows:

 

- it echos the new message i recieve

- i have to manually refresh the page for the right image to appear and onc ei read the new message i have to refresh the page again and the picture changes to the appropriate one.

-only problem is ajax dsnt seem to change the pics.

 

 

hmm?

 

maybe you do the select before the update? thats why you need to refresh the page to have your updated record read

 

-only problem is ajax dsnt seem to change the pics.  <<< what do you mean and how do you call the ajax where is it?

 

Link to comment
Share on other sites

the AJAX and php are in the same file. i will post the code below. one frame on my page is the file i will post below:

 

<?php 
session_start(); 
include "includes/db_connect.php"; 
include"includes/functions.php"; 
logincheck();
$username=$_SESSION['username'];
$query=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($query);
$inbox_msg=mysql_num_rows(mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='$username'"));
$check = mysql_query("SELECT `to`,`read` FROM `inbox` WHERE `read`='0' AND `to`='$username'");


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<script language="javascript">
function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
     alert("Your Browser Does Not Support This Script - Please Upgrade Your Browser ASAP");
   }

   return req;

}

// Make the XMLHttpRequest object
var http = createRequestObject();

function sendRequest(page) {

   // Open PHP script for requests
   http.open('get', page);
   http.onreadystatechange = handleResponse;
   http.send(null);

}

function handleResponse() {

   if(http.readyState == 4 && http.status == 200){

      // Text returned FROM the PHP script
      var response = http.responseText;

      if(response) {
         // UPDATE ajaxTest content
         document.getElementById("msgstatus").innerHTML = response;
      }

   }

}

function repeatloop()
{
sendRequest('box.php'); // replace "inbox-status.php" with your php page's url
setTimeout("repeatloop()", 3000);
}

window.onload=function() {
repeatloop();
}
</script>

<title>The Legendary Mafia</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-image: url(images/banner/gradient.gif);
background-repeat: repeat-x;
}
-->
</style></head>

<body>

<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="100%" height="70" background="" scope="col">
  <div align="center"><p>
        <?php

$inbox=mysql_num_rows($check);
if ($inbox > 0){ 
echo "<a href=inbox.php target=middle><img border=0 src=images/unread1.gif align=center  width=16 height=11></a> "; 
}else{ 
echo "<img src=images/read.gif align=center width=16 height=11>";
} 

?>
      <span id="msgstatus"></span></p>
      </div></td>
  </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

you have to explain this line

 

how can i refresh the info without page refresh, any unique ways to some how have a live connection with the server or something?

i dont think that is possible wit php  but you can try frames you have the other part of the frame refresh every given seconds until finds new info

 

does that make sense ?

Link to comment
Share on other sites

i want the frame to display one pic if the user has new messages and another different pic if it dsnt. Before i used html to auto refresh page every 10 secs.

 

that was annoying for the user. as the user could notice the refresh and the images used to flicker.

 

i found out that AJAX could perfrom the refresh for me better hence i tried usign that.

 

but the frame dsnt refresh automatically, but it does display correct info when i refresh manually.

Link to comment
Share on other sites

Alright well this is the best i could do, i noticed that your script is javascript,

dont know if that matters. if you could lay out what the javascript is doing

that would be great. As well if you could go to a free hosting site like racyspace.com

and put your stuff so that we can see what is going on it would be much appreciated.

 

<?php 
session_start(); 
require_once('includes/db_connect.php'); 
require_once('includes/functions.php'); 
logincheck();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<script type="text/javascript">
		function createRequestObject() {
			var req;
			if(window.XMLHttpRequest) {
				// Firefox, Safari, Opera...
				req = new XMLHttpRequest();
			} 
			else if(window.ActiveXObject) {
				// Internet Explorer 5+
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			else {
				// There is an error creating the object,
				// Just as an old browser is being used.
				alert("Your Browser Does Not Support This Script - Please Upgrade Your Browser ASAP");
			}
			return req;
		}
		// Make the XMLHttpRequest object
		var http = createRequestObject();
		function sendRequest(page) {
			// Open PHP script for requests
			http.open('get', page);
			http.onreadystatechange = handleResponse;
			http.send(null);
		}
		function handleResponse() {
			if(http.readyState == 4 && http.status == 200){
				// Text returned FROM the PHP script
				var response = http.responseText;
				if(response) {
					// UPDATE ajaxTest content
					document.getElementById("msgstatus").innerHTML = response;
				}
			}
		}
		function repeatloop() {
			sendRequest('inbox.php'); 
			// replace "inbox-status.php" with your php page's url
			setTimeout("repeatloop()", 3000);
		}
	</script>
	<title>The Legendary Mafia</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<style type="text/css">
		<!--
			body {
				background-image: url(images/banner/gradient.gif);
				background-repeat: repeat-x;
			}
		-->
	</style>
</head>
<body onload="repeatloop()">
	<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td width="100%" height="70" scope="col">
				<div align="center">
					<?php
						$inbox_user = $_SESSION['username'];
						$inbox_query = mysql_query("SELECT * FROM inbox WHERE read='0' AND to='" . $inbox_user . "'");
						$inbox_array = mysql_fetch_array($inbox_query);
						$inbox_num = mysql_num_rows($inbox_query);
						if($inbox_num > 0){ 
							print '<a href=inbox.php target=middle>';
							print '<img border=0 src=images/unread1.gif align=center width=16 height=11>';
							print '</a>'; 
						}
						else{ 
							print '<img src=images/read.gif align=center width=16 height=11>';
						} 
					?>
					<span id="msgstatus"></span>
				</div>
			</td>
		</tr>
	</table>
</body>
</html>

Link to comment
Share on other sites

$inbox_user = $_SESSION['username'];

 

is where you set the user name to use in the selection from the database.

 

$inbox_query = mysql_query("SELECT * FROM inbox WHERE read='0' AND to='" . $inbox_user . "'");

 

is the query. it is the exact same query you are using

 

which is

 

mysql_query("SELECT `to`,`read` FROM `inbox` WHERE `read`='0' AND `to`='$username'");

 

try

 

print $_SESSION['username'];

 

and

 

print mysql_error();

Link to comment
Share on other sites

Mr_mind i did what you said and got the following results:

 

- i echoed the two things and got:

 

WentWorthYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read='0' AND to='WentWorth'' at line 1

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\game\box.php on line 75

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\game\box.php on line 76

 

this shows that the $username variable picks up the correct username but i dn't know why the SQL statement is suggested to be incorrect.

 

- the image is shown but the correct image is not displayed, and even when i manually refresh the frame the correct image is not shown

 

so thats the problem now :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.