RE: [PHP-DB] Selecting next ID and less?

From: Date: Tue, 22 Apr 2003 23:55:54 +0000
Subject: RE: [PHP-DB] Selecting next ID and less?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-27287@lists.php.net to get a copy of this message
> I'm working on a puzzle game, where users must solve many different > puzzles. Once they complete a puzzle, they will be able to try the next > puzzle. Each puzzle is stored as a row in the puzzle in a database > table. The problem is, how would I select the puzzles the next highest > puzzle and lower? I could use a query something like "select * from > puzzles where id <= $completedid + 1", but it would break is there were > any holes in the ID. Also, it would use the ID as something more than a > unique identifier for each row, which is a bad thing. Any suggestions > for a better way? Assuming you're the puzzle_id you're currently solving is $puzzle Next Puzzle: SELECT * FROM table WHERE puzzle_id > $puzzle ORDER BY puzzle_id ASC LIMIT 1 Previous Puzzle: SELECT * FROM table WHERE puzzle_id < $puzzle ORDER BY puzzle_id DESC LIMIT 1 If no row is returned it means you're at the upper/lower limit. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.db (#27287) next »