shortysbest Posted November 27, 2010 Share Posted November 27, 2010 I am building a commenting system, it's sort of like facebooks comments. I have it right now so it loads the first last 3 comments in the database, and then there's a button to view all comments. I have it working fine, except when you add another comment to it, and then click the view all comments, This is the script that loads onload showing the last 3 comments $limit = 3; $query5 = mysql_query("SELECT * FROM sub_comments WHERE status_id='$id' ORDER BY id DESC LIMIT $limit"); This is the php script that runs when you click view more //($start_id would be 3 in this case) $query5 = mysql_query("SELECT * FROM sub_comments WHERE status_id='$comment_id' ORDER BY id DESC LIMIT $start_id, 1000"); so to try to show you what's happening: OnLoad--------------------------------|---When you add more comments, (let's just say u add 1 comment before u click view comments)---- comment 9 --------------------------| comment 10 comment 8 --------------------------| comment 9 comment 7 --------------------------| comment 8 ------------------------------------------| comment 7 ----to be loaded onclick-------------|------What's loaded onclick--- comment 6 --------------------------| comment 7 comment 5 --------------------------| comment 6 comment 4 --------------------------| comment 5 comment 3 --------------------------| comment 4 comment 2 --------------------------| comment 3 comment 1 --------------------------| comment 2 ------------------------------------------| comment 1 (see how "comment 7" is being shown twice in a row) Quote Link to comment Share on other sites More sharing options...
noXstyle Posted November 27, 2010 Share Posted November 27, 2010 Hi there! You're using ajax right? If not, then there is just something plain wrong with your code... but anyhow: how are you getting the value to $start_id? (you should really use more descriptive variables) just pass a variable to your 'view more' function stating whether a new comment has been added or not and increase your '$start_id' value in case there is a new comment. could be a better way depending on how you've written your code but thats one solution that works for sure .. Quote Link to comment Share on other sites More sharing options...
shortysbest Posted November 27, 2010 Author Share Posted November 27, 2010 I am using ajax, yes. $start_id is the same ass $limit. $limit is an id on the view more button, once you click that it activates the ajax function which then passes that data to the php page to load more of the comments, which is where $start_id comes from, it's just the same as $limit, just on another page. The way my code is currently I wouldn't really be able to just add 1 for each comment submitted, however the fix should be just a few minute process, which I am doing right now. Thank you. 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.