Worqy Posted April 23, 2010 Share Posted April 23, 2010 Hi. I working on a chat program. Now I get a problem when I use JS for updating the chat message textarea. Here is the codes: <?php /* chat.php */ Session_start(); ?> <head> <!-- Javascript --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script type="text/javascript"> function updateTable() { $("#chatlog").load('getmessage.php'); } setInterval("updateTable()",1000); </script> </head> <form method="POST" action="sendmessage.php"> <body bgcolor="gray"> <center><h2>Chat</h2></center> <center> <textarea name="chatlog" id="chatlog" cols=70 rows=20> </textarea> <textarea name="chatmessage" cols=62 rows=1> </textarea> <input type="submit" name="send" value="Send"> <center> <a href="getmessage.php">Get Message</a> </body> </form> <?php /* getmessage.php */ Session_start(); include 'config.php'; // Connect to MySQL $connect = mysql_connect("$host", "$username", "$password")or die("Cannot connect to MySQL"); mysql_select_db("$database")or die("Cannot select database!"); $sql = mysql_query("SELECT * FROM messages")or die(mysql_error()); while($row = mysql_fetch_array( $sql )) { $_SESSION['user'] = $row['user']; $_SESSION['message'] = $row['message']; echo "[" . $row['time'] . "]" . $row['user'] . " > " . $row['message']; } ?> Now I have two problems. 1) When I post a new message every message comes on the same row in the textarea. And if I edit the code like this: echo "[" . $row['time'] . "]" . $row['user'] . " > " . $row['message'] . "<br />"; It post the <br /> in the textarea. 2) All the messages are posted in the wrong ord. It starts from the oldest message and show the newest last ( This might be fixed if my problem one ( 1 ) is fixed ) // Kevin Link to comment https://forums.phpfreaks.com/topic/199495-problem-when-combinating-js-php-and-html/ Share on other sites More sharing options...
Ken2k7 Posted April 23, 2010 Share Posted April 23, 2010 Use \n Link to comment https://forums.phpfreaks.com/topic/199495-problem-when-combinating-js-php-and-html/#findComment-1047048 Share on other sites More sharing options...
Worqy Posted April 23, 2010 Author Share Posted April 23, 2010 Use \n Thanx. But it did not solve problem 2). It shows the oldes message first and the newest last. Example: [15:52:49]Admin > hhh [15:35:05]Admin > Row two [15:34:49]Admin > Row One Link to comment https://forums.phpfreaks.com/topic/199495-problem-when-combinating-js-php-and-html/#findComment-1047107 Share on other sites More sharing options...
Worqy Posted April 24, 2010 Author Share Posted April 24, 2010 I have now fixed my problem two ( 2 ). Anyone who know somekind of script that would help me refreshing the chat log ? Because the Javascript I'm using now isn't soo good because the textarea "blinks" everytime it updates Link to comment https://forums.phpfreaks.com/topic/199495-problem-when-combinating-js-php-and-html/#findComment-1047531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.