mike1313 Posted November 27, 2007 Share Posted November 27, 2007 Well with the following code I can't seem to limit the amount of messages displayed. I'm think maybe the last 15 messages but I can't get it to work. Any help? $sql = "SELECT message_id, user_name, message, date_format(post_time, '%h:%i') as post_time FROM message WHERE message_id > $last"; $message_query = db_query($sql); if(db_num_rows($message_query) > 0) { $json .= '"message":[ '; while($message_array = db_fetch_array($message_query)) { $json .= '{'; $json .= '"id": "' . $message_array['message_id'] . '", "user": "' . $message_array['user_name'] . '", "text": "' . $message_array['message'] . '", "time": "' . $message_array['post_time'] . '" },'; I've tried using ORDER BY in the sql statement also and that didn't work. Like it I used $sql = "SELECT message_id, user_name, message, date_format(post_time, '%h:%i') as post_time FROM message WHERE message_id > $last ORDER BY id ASC LIMIT 1"; It starts off displaying the message then another message appears everytime it refreshes and its just a continuous cycle. Any help or thoughts on how I can get this working the correct way is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
mike1313 Posted November 27, 2007 Author Share Posted November 27, 2007 Now I've tried using something like ORDER BY Lines-15, 15 and it displays the last 15 messages but it stopped auto-refreshing on submit. I'm so confused! Quote Link to comment Share on other sites More sharing options...
beamerrox Posted November 30, 2007 Share Posted November 30, 2007 are you making sure to end the JSON each time? i could see each refresh MAYBE it adds the message to the current JSON session Quote Link to comment Share on other sites More sharing options...
mike1313 Posted November 30, 2007 Author Share Posted November 30, 2007 I think so. $json .= '{'; $json .= '"id": "' . $message_array['message_id'] . '", "user": "' . $message_array['user_name'] . '", "text": "' . $message_array['message']. '", "time": "' . $message_array['post_time'] . '" },'; } $json .= ']'; } else { //Send an empty message to avoid a Javascript error when we check for message length in the loop. $json .= '"message":[]'; } } //Close our response $json .= '}}'; echo $json; I really don't know why it won't work because without limiting the query to the database is bogging down my server. 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.