Hi, I currently have a table which consists of user information and lesson id; the table layout looks like:
----------------------------------------------------
|employeeID|numVisits|lessonID1|lessonID2|lessonID3|
----------------------------------------------------
|33388 |2 |1 |0 |3 |
and a lessons table which contains the information about the lesson:
------------------------------------------------------
|lessonID |cateogry |title |filepath |numberviews|
------------------------------------------------------
|1 |beginner |lesson |file:// |10 |
Within the lessonID fields in the user table is an integer which tracks how many times someone has clicked on a lesson. Now what I am trying to do is in a report I have the top 5 people who have visited the site and would like to then be able to drill down into what lessons they have clicked on. Can anyone help with this? Or would restructuring the way the database is be an easier task?
Thanks
The way i have been looking at it so far is:
1 - get all the lessonID columns for a specific employeeID
2 - check which ones have a value greater than 0
3 - using the list in step 2 then query the lessonID on the user table for the corresponding title.
Step 1:
$sql = mysql_query("SELECT * FROM users
WHERE employeeID = 15110") or die(mysql_error());
$columns = mysql_num_fields($sql);
for($i = 0; $i < $columns; $i++) {
if(substr(mysql_field_name($sql, $i),0, 8) == "lessonID"){
$lessons[] = mysql_field_name($sql,$i).", ";
}
};
$lessonID = array_unique($lessons);
$l = substr("SELECT ".implode($lessonID)."", 0, -2)." FROM users WHERE employeeID = 15110";
This is where I am now at a loss, the above $l constructs the query to select all lessonID columns in the user table with a specific employeeID. However I am at a loss as to where to go next with the query result.