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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 13, 2007 Author Share Posted December 13, 2007 so then what is the problem? Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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?? ??? Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 18, 2007 Author Share Posted December 18, 2007 help please Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 18, 2007 Share Posted December 18, 2007 how do you call you ajax? Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 19, 2007 Author Share Posted December 19, 2007 what do you mean call? Quote Link to comment 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?  Quote Link to comment 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> Quote Link to comment 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 ? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 19, 2007 Share Posted December 19, 2007 can i see your site? Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment 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 Quote Link to comment 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.... Â Â Â Quote Link to comment 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 . "'"); Quote Link to comment 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(); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 . "'"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.