Okay you probably need to do something like this:
Code:
# Custom column definitions
CREATE TABLE `UserColumns` (
`UC_KeyID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`UC_UserID` INT UNSIGNED NOT NULL,
`UC_Order` INT UNSIGNED NOT NULL,
`UC_Title` VARCHAR(255) NOT NULL,
INDEX (`UC_UserID`),
UNIQUE (`UC_KeyID`)
);
# Individual entries
CREATE TABLE `UserEntries` (
`UE_KeyID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`UE_Column` INT UNSIGNED NOT NULL,
`UE_Date` INT UNSIGNED NOT NULL,
`UE_Value` INT NOT NULL,
INDEX (`UE_Column`),
UNIQUE (`UE_KeyID`)
);
# Create 3 columns each for 2 different user ids
INSERT INTO UserColumns (UC_UserID, UC_Order, UC_Title)
VALUES (1, 1, 'Test Column 1'), (1, 2, 'Test Column 2'), (1, 3, 'Test Column 3'), (2, 1, 'Happy Meals'), (2, 2, 'Sex Toys'), (2, 3, 'Yoga Lessons');
# Populate 3 days of entries for each column
INSERT INTO UserEntries (UE_Column, UE_Date, UE_Value)
VALUES (1, 1208707200, 4000), (1, 1208793600, 3000), (1, 1208880000, 5000),
(2, 1208707200, 3000), (2, 1208793600, 2000), (2, 1208880000, 9000),
(3, 1208707200, 7000), (3, 1208793600, 5000), (3, 1208880000, 4000),
(4, 1208707200, 8000), (4, 1208793600, 8000), (4, 1208880000, 2000),
(5, 1208707200, 1000), (5, 1208793600, 7000), (5, 1208880000, 6000),
(6, 1208707200, 9000), (6, 1208793600, 1000), (6, 1208880000, 8000);
# Display user 1's data
SELECT YEAR(FROM_UNIXTIME(UE_Date)) AS UE_Year, MONTH(FROM_UNIXTIME(UE_Date)) AS UE_Month, DAY(FROM_UNIXTIME(UE_Date)) AS UE_Day, UC_Title, UE_Value
FROM UserEntries, UserColumns WHERE UC_UserID = 1 AND UE_Column = UC_KeyID
GROUP BY UC_KeyID, UE_Year, UE_Month, UE_Day
ORDER BY UC_Order, UE_Year ASC, UE_Month ASC, UE_Day ASC, UC_Title ASC;
# Change the row order
UPDATE UserColumns SET UC_Order = CASE UC_KeyID
WHEN 1 THEN 2
WHEN 2 THEN 3
WHEN 3 THEN 1
ELSE UC_Order END;
# Display user 1's data again
SELECT YEAR(FROM_UNIXTIME(UE_Date)) AS UE_Year, MONTH(FROM_UNIXTIME(UE_Date)) AS UE_Month, DAY(FROM_UNIXTIME(UE_Date)) AS UE_Day, UC_Title, UE_Value
FROM UserEntries, UserColumns WHERE UC_UserID = 1 AND UE_Column = UC_KeyID
GROUP BY UC_KeyID, UE_Year, UE_Month, UE_Day
ORDER BY UC_Order, UE_Year ASC, UE_Month ASC, UE_Day ASC, UC_Title ASC;
# Display user 2's data, newest first
SELECT YEAR(FROM_UNIXTIME(UE_Date)) AS UE_Year, MONTH(FROM_UNIXTIME(UE_Date)) AS UE_Month, DAY(FROM_UNIXTIME(UE_Date)) AS UE_Day, UC_Title, UE_Value
FROM UserEntries, UserColumns WHERE UC_UserID = 2 AND UE_Column = UC_KeyID
GROUP BY UC_KeyID, UE_Year, UE_Month, UE_Day
ORDER BY UC_Order, UE_Year DESC, UE_Month DESC, UE_Day DESC, UC_Title DESC;
Displaying the results in a tabular format is left as an exercise for the reader.