Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Real Time Updating With Ajax, I need a bit help with ajax in this real time chat script.
ewcreators
post Oct 21 2007, 01:58 PM
Post #1


Member [Level 1]
****

Group: Members
Posts: 59
Joined: 28-August 07
Member No.: 48,983



CODE
<script type='text/javascript'>
function submitForm()
{
    var xhr;
    try { xhr = new XMLHttpRequest();
}                
    catch(e)
    {    
      xhr = new ActiveXObject(Microsoft.XMLHTTP);
    }

xhr.onreadystatechange =function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)

document.getElementById('c').innerHTML="SENT";
else
document.ajax.dyn.value="ERROR CODE" + xhr.status;
}
};
var data=document.ajax.dyn.value;
//var chat=document.ajax.ba.value;
var final="&content="+data;
xhr.open("GET","chat2.php?ba=<?php echo $_GET[a];?>" +final,true);
xhr.send(data);
}




</script>

<?php
require('connection2.php');
require('sessions.php');
require('details.php');
$sel=mysql_query("SELECT * FROM `chat` ORDER BY `id` LIMIT 1,6 ");
echo "<table border='1'> <tr><th colspan=2>SIDECHAT</th></tr><tr><td colspan=2>";
while($row=mysql_fetch_array($sel)) {
echo "<font color='yellow'><b>".$row['name']."</b></font>:<font color='gray'>".$row['content']."</font><br />";
}
echo "</td></tr><br /><tr><td colspan=2> <div id='c'> </div></tr></td></tr>";
echo "<tr><td colspan=1><FORM method='POST' name='ajax' action=''><INPUT type='text' name='dyn' maxlength='40'></td><td><input type='submit' onClick='submitForm()' value='>' ></td></tr>";

require('links.php');
?>


Now when that result shows, (it comes real time afcourse), how can i get others to show their results real time without have the current user to refresh/go to a different page?
like msn ..etc you get the results directly real time/at the same time.
How can i go about that?
Also, i want to keep upto 6 results in my real time chat box, but the only method i know is off 1,6...which will only select the first 6 rows..please help!
Go to the top of the page
 
+Quote Post
galexcd
post Oct 22 2007, 07:20 PM
Post #2


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
*********

Group: [HOSTED]
Posts: 975
Joined: 25-September 05
From: The dungeon deep below the foundation of trap17
Member No.: 12,251



QUOTE(ewcreators @ Oct 21 2007, 06:58 AM) *
Now when that result shows, (it comes real time afcourse), how can i get others to show their results real time without have the current user to refresh/go to a different page?

Are you asking how to get other results? Why don't you just make a function that sends tat via ajax, and then call it again with a settimeout function?


QUOTE(ewcreators @ Oct 21 2007, 06:58 AM) *
Also, i want to keep upto 6 results in my real time chat box, but the only method i know is off 1,6...which will only select the first 6 rows..please help!


Once again, I am sorry but I just don't always know what your asking exactly. I believe your delema is that its only selecting the first 6 rows insted of the most recent 6 rows am i right? This could be solved by using the ORDER BY in sql. I see you have ORDER BY `id` already but it is in the wrong order. You want to add DESC after that
CODE
ORDER BY `id` DESC

to reverse the order that it gets the results by.
Go to the top of the page
 
+Quote Post
ewcreators
post Oct 23 2007, 04:09 PM
Post #3


Member [Level 1]
****

Group: Members
Posts: 59
Joined: 28-August 07
Member No.: 48,983



ok...show me the settimeout part please smile.gif coz i wont know how to fit it into all this real timey :/

Also, now http://revolutions.ifastnet.com/main/chat3.php?a=test
(that is the one i showed) is not coming real timey :/
It loads ohmy.gifohmy.gif
I mean, when i click on the send text button, it loads the page again :/
Go to the top of the page
 
+Quote Post
ewcreators
post Oct 23 2007, 04:12 PM
Post #4


Member [Level 1]
****

Group: Members
Posts: 59
Joined: 28-August 07
Member No.: 48,983



btw, your ORDER BY `id` DESC idea didnt work tongue.gif
it just grabbed the rows 1,6 which were desc in id order.
meaning id 1,2,3,4,5,6
Go to the top of the page
 
+Quote Post
sonesay
post Oct 23 2007, 07:18 PM
Post #5


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 643
Joined: 20-June 07
From: Auckland
Member No.: 45,102



I did a search on google and found this.

http://particletree.com/notebook/select-last-100-records/

CODE
SELECT RecordId
FROM Table
WHERE RecordId
IN (
SELECT RecordId
FROM Table
ORDER BY RecordId DESC
LIMIT 100
)
ORDER BY RecordId ASC


as for setTimeOut()

I've used it twice.I think this would work
CODE

function Ajax*() {
...
..

setTimeOut('Ajax*();', 2000 );
}


I think what you want to use for this function is for <body onload='' so that it start right away refreshing the post. Im not sure how it will work when you submit the from with another ajax update. I think it will continue working. Good luck.

This post has been edited by sonesay: Oct 23 2007, 07:25 PM
Go to the top of the page
 
+Quote Post
galexcd
post Oct 23 2007, 08:26 PM
Post #6


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
*********

Group: [HOSTED]
Posts: 975
Joined: 25-September 05
From: The dungeon deep below the foundation of trap17
Member No.: 12,251



QUOTE(ewcreators @ Oct 23 2007, 09:12 AM) *
btw, your ORDER BY `id` DESC idea didnt work tongue.gif
it just grabbed the rows 1,6 which were desc in id order.
meaning id 1,2,3,4,5,6


Your limit 1,6 is messing it up because it's counteracting with the order. Just type LIMIT 6... that will limit it to the last 6 rows.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Video Games Are A Complete Waste Of Time, Face It!(145)
  2. Could Someone Make A Php Script For Me?(3)
  3. Name 3 Things That Make You Real Mad(78)
  4. Is wwe wrestling Real or Fake ??????(45)
  5. Teamspeak 2 Vs Ventrilo(10)
  6. How To Find Real Pearl(6)
  7. Worst Game Of All Time(60)
  8. How Do I Make A Live Chat Using Php?(15)
  9. Watermark Your Image With Simple Php Script(34)
  10. Indian Cricket(58)
  11. How Do I Make My Own Private Online Server Please Help Me Out.thank You For Your Time.(22)
  12. Boltblue: Beware!(14)
  13. Lock Ness Monster(23)
  14. Google Chat -- Blocked ?(4)
  15. Background Image Swap Script(15)
  1. Integrity Checks Failing During Multiple Ajax Request(1)
  2. Invite Script..(2)
  3. Loaing Script(3)
  4. Ie 7 Issue With Ajax(2)
  5. Firefox 3 Sucks - Time For Another Browser(48)
  6. Debate With The Religions : Christian Vs Islam Vs More(15)
  7. Another Cust. Service Rant... This Time As A Customer(5)
  8. How To Make A View New Post Script?(5)
  9. Phpizabi Social Network Script(1)
  10. Firefox Updates(3)
  11. Story Time!(2)
  12. Date Time Lights Temp And Timer, It's Go It All(0)
  13. Php Guest Online Script(2)


 



- Lo-Fi Version Time is now: 26th July 2008 - 07:57 AM