RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 the right image showed before i thought of implementing the AJAX script, the automatic refresh at 10 seconds using html worked just fine, but ever since i tried using ajax to refresh i get this problem. Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-413437 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 i believe your if's works fine to check print the result of yur query to see the content Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-413445 Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 so then what is the problem? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-413447 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 <?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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-413450 Share on other sites More sharing options...
RealDrift Posted December 14, 2007 Author Share Posted December 14, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-415021 Share on other sites More sharing options...
RealDrift Posted December 14, 2007 Author Share Posted December 14, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-415227 Share on other sites More sharing options...
RealDrift Posted December 16, 2007 Author Share Posted December 16, 2007 come on there must be a solution?? ??? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-415881 Share on other sites More sharing options...
RealDrift Posted December 18, 2007 Author Share Posted December 18, 2007 help please Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-417271 Share on other sites More sharing options...
teng84 Posted December 18, 2007 Share Posted December 18, 2007 how do you call you ajax? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-417275 Share on other sites More sharing options...
RealDrift Posted December 19, 2007 Author Share Posted December 19, 2007 what do you mean call? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418055 Share on other sites More sharing options...
teng84 Posted December 19, 2007 Share Posted December 19, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418090 Share on other sites More sharing options...
RealDrift Posted December 19, 2007 Author Share Posted December 19, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418092 Share on other sites More sharing options...
teng84 Posted December 19, 2007 Share Posted December 19, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418100 Share on other sites More sharing options...
RealDrift Posted December 19, 2007 Author Share Posted December 19, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418102 Share on other sites More sharing options...
teng84 Posted December 19, 2007 Share Posted December 19, 2007 can i see your site? Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418105 Share on other sites More sharing options...
RealDrift Posted December 19, 2007 Author Share Posted December 19, 2007 its not online, but on my pc btw i think the page is refreshing, but each time it refreshes it just displays a duplicate image below, and more images appear wtf? i added exit(); at the end and no more duplicate images Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418107 Share on other sites More sharing options...
mr_mind Posted December 19, 2007 Share Posted December 19, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418252 Share on other sites More sharing options...
RealDrift Posted December 19, 2007 Author Share Posted December 19, 2007 mr mind ur script didnt work. it said that the mysql query was not right, the "to" bit. teng i just added exit(); at the end of php script thats all Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418372 Share on other sites More sharing options...
redarrow Posted December 19, 2007 Share Posted December 19, 2007 mr minds code is correct echo the select statement out ok.... Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418385 Share on other sites More sharing options...
RealDrift Posted December 19, 2007 Author Share Posted December 19, 2007 mr minds code is correct echo the select statement out ok.... having probs with this line, gives me an error: $inbox_query = mysql_query("SELECT * FROM inbox WHERE read='0' AND to='" . $inbox_user . "'"); Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418394 Share on other sites More sharing options...
mr_mind Posted December 19, 2007 Share Posted December 19, 2007 $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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-418453 Share on other sites More sharing options...
RealDrift Posted December 21, 2007 Author Share Posted December 21, 2007 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 https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-420131 Share on other sites More sharing options...
teng84 Posted December 21, 2007 Share Posted December 21, 2007 $inbox_query = mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='" . $inbox_user . "'"; try Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-420138 Share on other sites More sharing options...
RealDrift Posted December 21, 2007 Author Share Posted December 21, 2007 $inbox_query = mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='" . $inbox_user . "'"; try Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\game\box.php on line 70 Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-420146 Share on other sites More sharing options...
teng84 Posted December 21, 2007 Share Posted December 21, 2007 sorry! $inbox_query = mysql_query("SELECT * FROM `inbox` WHERE `read`='0' AND `to`='" . $inbox_user . "'"); Link to comment https://forums.phpfreaks.com/topic/81283-refresh-problem/page/2/#findComment-420150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.