Jump to content

Refresh problem


RealDrift

Recommended Posts

Hi,

 

An AJAX script refreshes a file containing the following code:

 

logincheck();
$username=$_SESSION['username'];
$viewuser=$_GET['viewuser'];

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

$inbox=mysql_num_rows($check);

<TD width="4%" align="left" valign="middle"><span id="msgstatus"><span class="style2">
		      <?php 
			  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>"; } 
		      
			   ?>
			  </span></span></TD>

 

The AJAX script is fine and tested, the guy who tested the script said there is something wrong with my php. is there anything wrong with my script?

 

the above script basically displays one pic if there are unread messages in your inbox and if there aren't any then it displays a completely different picture.

Link to comment
Share on other sites

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

It would help if you organized your code at all because i found lots of errors.

 

<?php
if(logincheck()) {
	if(isset($_SESSION['username']) && isset($_GET['viewuser'])) {
		$inbox_user = $_SESSION['username'];
		$inbox_view = $_GET['viewuser'];
		$inbox_num_query = mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='$username'");
		$inbox_num = mysql_num_rows($inbox_num_query);
		print '<td width=4% align=left valign=middle>';
		print '<span id=msgstatus class=style2>';
		print '<a href=inbox.php target=middle>';
		print '<img border=0 align=left src=images/';
		if($inbox_num > 0) {
			print 'unread1';
		}
		else { 
			print 'read';
		}
		print '.gif width=16 height=11></a>';
		print '</span>';
		print '</td>';
	}
}
?>
[code]

[/code]

Link to comment
Share on other sites

Here is the php script where the message icon is meant to be displayed, it has the AJAx refresh code in it too:

 

<?php
session_start();
include "includes/db_connect.php";
include "includes/functions.php";
logincheck();
$username=$_SESSION['username'];
$viewuser=$_GET['viewuser'];

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

$inbox=mysql_num_rows($check);


$query=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($query);
$currank=$fetch->rank;

$fetch2=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'"));

?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link rel=stylesheet href=includes/in.css type=text/css>
<style type="text/css">
<!--
.style2 {font-size: 12}
.style3 {font-size: 11px}
-->
</style>

<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('refresh.php'); // replace "inbox-status.php" with your php page's url
setTimeout("repeatloop()", 3000);
}

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

</head>
<body>

<table

			width="110%" height="10" border="0" cellPadding="0" cellSpacing="0" bordercolor="#737373" class="thinline" id="Table1" style="LEFT: 0px; POSITION: absolute; TOP: 0px; height: 100%;" name="Table1">

			<tr valign="middle">

			  <td width="4%" align="left" valign="middle"><div align="center"><span id="msgstatus">the span tags are here for the AJAx refresh script</span></div></td>

			  <td width="96%" bgcolor="#737373"><span class="style3"><strong>Rank: </strong> </b></font></a>				</span></td>
		    </tr>
</table>

</body>

</html>

 

 

this is the php script which determines what pic to display:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php

include "includes/db_connect.php";
include "includes/functions.php";
if(logincheck()) {
	if(isset($_SESSION['username']) && isset($_GET['viewuser'])) {
		$inbox_user = $_SESSION['username'];
		$inbox_num_query = mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='$username'");
		$inbox_num = mysql_num_rows($inbox_num_query);
		print '<td width=4% align=left valign=middle>';
		print '<span id=msgstatus class=style2>';
		print '<a href=inbox.php target=middle>';
		print '<img border=0 align=left src=images/';
		if($inbox_num > 0) {
			print 'unread1';
		}
		else { 
			print 'read';
		}
		print '.gif width=16 height=11></a>';
		print '</span>';
		print '</td>';
	}
}
?>
</body>
</html>

 

there you have it, anything wrong with the above?

Link to comment
Share on other sites

basically the AJAX script works fine and refresh the text between the span tags. It displays text, however it doesn't seem to show the images in the php script.

 

It should refresh to show one image if user has new messages and refresh to show another image if user has no new messages. But it dsnt display either pic.

 

does that help?

Link to comment
Share on other sites

if you dont put this

 

print '<img border=0 align=left src=images/';

        if($inbox_num > 0) {

            print 'unread1';

        }

        else {

            print 'read';

        }

        print '.gif width=16 height=11>

 

and simply 

print '<img border="0" align="left" src="images/unread1.gif" width="16" height="11">';

        does it work?

Link to comment
Share on other sites

now i undid to the original code and gt this error:

 

 

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\game\refresh.php:9) in C:\xampp\htdocs\game\includes\functions.php on line 2

 

:(

Link to comment
Share on other sites

	print "<img border='0' align='left' ";
        if($inbox_num > 0) {
            print "src='images/unread1.gif";
         }
         else {
            print "src='images/read.gif";
         }
         print " width='16 height='11' />";

retain your old code and add this part

Link to comment
Share on other sites

mr_mind complicated the code for me. here is the original simple code :

 

<?php
session_start();
include "includes/db_connect.php";
include "includes/functions.php";
logincheck();
$username=$_SESSION['username'];

$viewuser=$_GET['viewuser'];

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

$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>"; } 
		      

?>

Link to comment
Share on other sites

try this and tell me what happen

<?php
session_start();
include "includes/db_connect.php";
include "includes/functions.php";
logincheck();
$username=$_SESSION['username'];
$viewuser=$_GET['viewuser'];
$check = mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='$username'");
$inbox=mysql_num_rows($check);
if ($inbox > 0){ 
echo $inbox;
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>";
} 
echo "<a href=inbox.php target=middle><img border=0 src=images/unread1.gif align=left  width=16 height=11></a> "; 
?>

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.