I have a database that contains the course number for training that needs to be done as column names. Each time a new training form is added a new column is created for it. A 0 stands for uncompleted and a 1 stands for completed. I want to be able to get the course numbers(column names) for a specific person based on whether the value for the column is 1(complete). So it would have to iterate through all the columns to check if they are 1. But i am not going to know the names of the columns beforehand since a script dynamically adds new course numbers to the table. Any ideas?
CREATE TABLE Training(
id int NOT NULL AUTOINCREMENT,
username varchar(6) not null,
`9875` INT(2) NULL,
`875` INT(2) NULL,
`475` INT(2) NULL,
`9835` INT(2) NULL,
`375` INT(2) NULL,
`9872` INT(2) NULL,
INSERT INTO Training VALUES(kd4893,0,0,1,1,0,1,1,0)
So a query on kd4893 would return 475,9835,9872,9234.
Edit: Would it be simpler to do this in PHP?
This post has been edited by helpme18: 28 July 2014 - 06:15 PM