RealDrift Posted December 12, 2007 Share Posted December 12, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/ Share on other sites More sharing options...
mr_mind Posted December 12, 2007 Share Posted December 12, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-412523 Share on other sites More sharing options...
RealDrift Posted December 12, 2007 Author Share Posted December 12, 2007 i changed it and got error: Fatal error: Call to undefined function logincheck() Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-412527 Share on other sites More sharing options...
teng84 Posted December 12, 2007 Share Posted December 12, 2007 because your suppose to have this function logincheck() defined Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-412529 Share on other sites More sharing options...
RealDrift Posted December 12, 2007 Author Share Posted December 12, 2007 the function was defined in: include "includes/db_connect.php"; include "includes/functions.php"; i included those at the top now the error is gone, but no image, If i just echo image without an IF statement the image is displayed. Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-412530 Share on other sites More sharing options...
mr_mind Posted December 12, 2007 Share Posted December 12, 2007 could you post all of the code? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-412575 Share on other sites More sharing options...
RealDrift Posted December 12, 2007 Author Share Posted December 12, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413269 Share on other sites More sharing options...
teng84 Posted December 12, 2007 Share Posted December 12, 2007 can you tell us again what the problem your getting out of that code? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413275 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413311 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 how will the script determine if there is new image? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413321 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 look at the second code i just gave you: Lines: print '<img border=0 align=left src=images/'; if($inbox_num > 0) { print 'unread1'; } else { print 'read'; } print '.gif width=16 height=11></a>'; Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413325 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 can you give us the exact link to your images? and the source code of that pages when it runs on your browser? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413328 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 images/unread1.gif images/read.gif what source code? i have given you the main file source code which is the first code and the second code is the script which shows image according to status. Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413335 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413340 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 it shows the pic if there is no IF statements attached to it, like: print '<img border="0" align="left" src="images/unread1.gif" width="16" height="11">'; what could be wrong? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413350 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413355 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413372 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 i changed that part and then refreshed the page, no pic showed and when AJAX refresh the page second later i got that session error again Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413379 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 maybe your trying to use header before or after you use print or echo Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413385 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413389 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 i have put the IF statement back into the file which has the AJAX refresh script, between the span tags. now the first uread1.gif is displayed but it dsnt change to read.gif when i read the unread messages. Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413391 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413396 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 it echoes two images: read.gif and unread1.gif despite there being new messages. If i refresh the page manually the unread1.gif still is there. it doesn't change to read.gif like it should Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413402 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 where is the part that updates your db so that it tells you that you have read that inbox? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413410 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 that is in the inbox.php file line: mysql_query("UPDATE `inbox` SET `read`='1' WHERE `to`='$username'"); i know when i veiw inbox unread messages are marked as read, since i can see it all happen via the db Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/#findComment-413414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.