way to inserting data into a MYSQL table data in an ordered way

Status
Not open for further replies.

komrad

Banned
Nov 23, 2007
108
0
0
www.website.ws
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.
 


I don't know of any tools or frameworks that implement a linked list structure for MySQL. Certainly not anything built in. I guess I would probably just write my own POJOs (POPHPOs?) and DAOs for the objects represented by those tables.
 
Databases aren't designed to insert records in a particular order. The best way to code what I think you are trying to do is create a field that stores the position and sort by that field when you retrieve the records. If you need to insert a record at, for example, position 5 then you would use these two SQL commands:

UPDATE Table SET Position = Position + 1 WHERE Position >= 5;
INSERT INTO Table (Field1,Field2,Position) VALUES (Value1,Value2,5);
 
Databases aren't designed to insert records in a particular order. The best way to code what I think you are trying to do is create a field that stores the position and sort by that field when you retrieve the records. If you need to insert a record at, for example, position 5 then you would use these two SQL commands:

UPDATE Table SET Position = Position + 1 WHERE Position >= 5;
INSERT INTO Table (Field1,Field2,Position) VALUES (Value1,Value2,5);

you can't tell them exactly how to do it! Then use poor programmers make no money
 
Actually If u want data in a ordered way U can just implement a master-slave relationship between the tables I'm not sure whether i got ya problem right but wat i suggest is U make 2 tables of ya existing data then U can create a query to sort the records U better elobarate ya question for me i think i can get U the exact query or solution for U.
 
Status
Not open for further replies.