Page 1 of 1

I'm trying to show previous and nex comments - MySQL

Posted: Mon Apr 09, 2012 9:56 am
by lovelf

Code: Select all

$result=mysql_query("SELECT * FROM $usertagtc WHERE textid='$thetext' AND primary2>$aquery AND primary2<$aqueryv");
Primary2 is the primary index with an auto increment, the problem comes when the table gets edited and some "primarys" are deleted, then the clause is bigger than but less than wouldn't work appropriately, how to come up with a solution for this?

Re: I'm trying to show previous and nex comments - MySQL

Posted: Mon Apr 09, 2012 1:55 pm
by tr0gd0rr
You'll probably want to use MAX and MIN. For example to get the next comment: `SELECT MIN(primary2) WHERE primary2 > $currentCommentId`. And it would be even better if you used a date created column to compare. With AutoIncrement, there is no guarantee that ids will be in date order.