Jump to content

mysql Select Limit x,y..dont load last 3 rows


shortysbest

Recommended Posts

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)

Link to comment
Share on other sites

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 ..

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.