|
|
|
|
![]() ![]() |
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! |
|
|
|
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 |
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? 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. |
|
|
|
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
Also, now http://revolutions.ifastnet.com/main/chat3.php?a=test (that is the one i showed) is not coming real timey :/ It loads I mean, when i click on the send text button, it loads the page again :/ |
|
|
|
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
it just grabbed the rows 1,6 which were desc in id order. meaning id 1,2,3,4,5,6 |
|
|
|
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 |
|
|
|
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 |
btw, your ORDER BY `id` DESC idea didnt work 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. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 26th July 2008 - 07:57 AM |