php ve mysql kullanıcı izleme ve raporlama

3 Cevap php

Şu anda kullanıcı bilgileri ve ders id oluşan bir tablo var; masa düzeni gibi görünüyor:

----------------------------------------------------
|employeeID|numVisits|lessonID1|lessonID2|lessonID3|
----------------------------------------------------
|33388     |2        |1        |0        |3        |

ve ders hakkında bilgi içeren bir ders tablosu:

------------------------------------------------------
|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?

Teşekkürler


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.

3 Cevap

Şu anda çalışan sadece hiç 3 ders alabilir. Sen veri normalleştirmek için daha iyi yaparım. Bu gibi Belki bir şey:

employees
---------
emp_id
emp_name
etc.

visits
------
visit_id
visit_timestamp
emp_id

lessons
-------
lesson_id
lesson_title
etc.

emp_lessons
-----------
emp_id //FK to employees table
lesson_id //FK to lessons table
lesson_date

Sonra, birisi ziyaret etti ne sıklıkta bilmek istiyorum,

SELECT count(*) FROM visits WHERE emp_id=x

Ve birisi dersi 1. aldı kaç kere bilmek istiyorsanız:

SELECT count(*) FROM emp_lessons WHERE lesson_id=1 AND emp_id=x;

Eğer veritabanı tasarımı normalleştirmek gerek.

Lütfen çalışan ve ders tablolar arasında bir bağlantı tablo düşünün. Bu, birçok dersleri birçok çalışanı ilişki sağlar.

Örneğin:

çalışan masa

employee_id, num_visits

ders tablosu

lesson_id, category, title, filepath, numberviews

employee_ders tablosu

employee_id, lesson_id

Employee_id ve birleşik bir anahtar oluşturmak lesson_id.

Cevaplar ekleme burada benim iki sent:

Aşağıda eklenen tablo yapısını göz önüne alındığında, size ihtiyacınız veri ayıklamak için aşağıdaki sorguları gerekir:

Eğer aşağıdaki kullanmak tablo çalışanı vasıtasıyla Ziyaret aşağı izliyorsanız, sonuç siteyi ziyaret top 5 çalışanı olduğunu:

SELECT * FROM employee ORDER BY visits ASC 0,5

Eğer ziyaret tablosunu kullanarak eğer:

SELECT employee.*, count(visit.visitId) as visits FROM employee, visit WHERE employee.employeeId = visit.employeeId GROUP BY employee.employeeId ASC 0,5

finallly, her çalışanın erişilen ne dersleri kontrol etmek için, sadece bu kullanın:

SELECT * FROM employee WHERE employeeId = (SELECT employeeId FROM class GROUP BY lessonId)

Bunu şahsen ben böyle bir şey yapmak istiyorum, tasarımı yeniden gözden geçirilmesi gerektiğini:

**employee**
employeeId
employeeName
employeeLName
visits
lastVisit

Her ziyaretin tarihini ve saatini izini isterseniz tarih ve saat, ya da sadece son bir ilgi değilseniz, sadece çalışan tabloya alanları ekleyin, ziyaret, yeni bir tablo eklemek gerekir:

**visit**
visitId
visitDate
employeeId FK

**lesson**
lessonId
lessonName
lessonPath
lessonViews

**class** (or any name you see fit)
employeeId FK
lessonId FK
lessonDate (Last time the employee accessed the lesson)

Sorguları test etmek için yeterli zaman var ama biraz yardımcı olur umarım, en azından doğru yönde bir işaret gerektiğini düşünüyorum değil mi :)