This topic is locked

Deleting records from details table when deleting a record in the mast

12/22/2007 8:29:12 AM
PHPRunner General questions
J
jonas author

Hello
I am running a training program for driving tests. I have been using ASP and MS Access, but now I am going to move my stuff to MySql and PHP.

Thanks to PHP Runner, most of my things are running perfect. But my only problem (at the moment) is as follows:
I need two tables. Table one _studentswith list of students, their addresses etc. One field is ID (primary key)

The second table is _testswhere each student can have different records. I named one field StudentID (not the primary key).

In the table _studentsI have a student with the name John, ID = 1

In the table _testsI have 3 tests taken by John, all with the field StudentID = 1

When John has finished his study I want to delete all his data, simply by deleting his record in the _studentstable (in MS Accces this was very simple!).
First I thought it would be enough to set _studentsas a Master, ID as a primary key, and_testsas Detail, StudentID as foreign key. But that is not doing the job.

Reading the forum it seems obvious that I have to use Table event, List page, After record deleted. I found the following line of code in the forum and tried to use it:
$sql = "delete from _tests where StudentID=".$deleted_values["ID"];
But so far I get nothing happen! No error message, just the records in the table _testsare not deleted.

I am sure this as a minor problem - but I would be happy if someone could save me some time and tell me how to do this!
Best regards and merry Christmar from Iceland
Jonas

Alexey admin 12/24/2007

Jonas,
don't forget to run your SQL string after constructing it:

db_exec($sql,$conn);


If this doesn't help publish your project on Demo Account server (last tab in PHPRunner) and send a link to it to support@xlinesoft.com

I'll help you to get this working.