View Single Post
  #3 (permalink)  
Old 02-21-2009, 10:24 PM
troublescoot troublescoot is offline
Junior Member
 
Join Date: Feb 2009
Posts: 20
troublescoot is on a distinguished road
Quote:
Originally Posted by komrad View Post
Hello all,

I'd like to know if there is a way to insert into a MYSQL table data in an ordered way?
Right now as a workaround I've literally made a table of questions with questionID as primary key, nextQuestion and prevQuestion pointing to other questionIDs. Basically I've made a two way linked list from scratch. Is there anything built into MYSQL that implements this?

Thanks in advance.
It seems like you want a way to automagically point to the previous/next records for navigational purposes.

If that's what it is, you can just do a query for each-

Code:
<?php

$previous = mysql_query(sprintf("SELECT questionID FROM [table] WHERE (questionID < %d) LIMIT 1", $currentQuestionId));

$next = mysql_query(sprintf("SELECT questionID FROM [table] WHERE (questionID > %d) LIMIT 1", $currentQuestionId));

?>
That's a very rudimentary way of doing it.

Not sure if that helps, but it's all I could do given the info.
Reply With Quote