Best way to organise my web database setup [simple help please]

Associate
Joined
6 Jul 2003
Posts
2,075
Building a bit of a personal learning project but not quite sure of best practices or standard ways to go about doing simple things yet so perhaps someone could lend a hand here:

I have 3 tables: cars, computers, books - and each one has it's own fields - cars has engine size and transmission, computers has CPU speed and ram, books has author, title etc. I want a user to be able to input a multiple amount of either (based on how many they own) which are saved one by one, and then when they're finished, it gives them an unheaded list of everything they typed in (as in, just prints all the fields in each record side by side), in the order they entered them.

If I had to guess, this is what I'd do: at first load, give the user a unique session id. As they enter their stuff, their session id goes into each item table against the item they just created. Then when they're finished, query all the tables by the session id and list the results. But how would I order them in the order they were input (as they're coming from different tables), and would it be possible to alter that order afterwards (by clicking a moveup/down button from the list).

Thanks to anyone who can shed any light.
 
You could do it by adding a new field sessionOrder

Cars
Code:
id sessionId sessionOrder engineSize transmission

Computers
Code:
id sessionId sessionOrder cpuSpeed ram

Books
Code:
id sessionId sessionOrder author title

Give a sessionId for the session and sessionOrder + 1 for each item.

So it could look like this:
Code:
BOOK
1, 1, 1, "Mr Man", "His Book"
2, 1, 3, "Mr Man", "His Second Book"
COMPUTER
1, 1, 2, "1Ghz", "1GB"
CAR
1, 1, 4, "1litre", "Some Transmission"

Get all results where the sessionId matches the current one, and order by sessionOrder. So it would output like this:

Book, Mr Man, His Book
Computer, 1Ghz, 1GB
Book, Mr Man, His Second Book
Car, 1litre, Some Transmission

Hopefully this makes sense, I just wrote it out quickly

Edit: And you can change the position afterwards by changing the sessionOrder
 
Back
Top Bottom