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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

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

Post 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?
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

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

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