开发者

The logic for retrieving a record on my database? MySQL PHP

I am about to begin my "Data Auditing" section of my site. What does that mean?

Well basically users can view and update records they have submitted to the database.

This is my first time doing this and I am guessing I will need to use Joins, Selects? etc.

So I was wondering if you could help me with the logic on how I will work through this query. I don't want code as I want to do it myself but the logic is what is bothering me.

Here is an image of my Database schema showing relationships etc:

The logic for retrieving a record on my database? MySQL PHP

http://i.imgur.com/Dju0G.png

开发者_Go百科This is what I have thought how to start (pseudocode):

-Get procedure row where procedure_id = posted value from previous page.

-Retrieve values from that row in procedure table.

-Get patient row that matches the foreign key value in procedure table.

-Get department row that matches the foreign key value in procedure table.

-Get procedure_name row that matches the foreign key value in procedure table.

-Get dosage row that matches the foreign key value in procedure table.

However after this point I am a bit stuck on how I deal with the Many-to-Many (n--> n) relationship tables , is this where a join comes in?

What about my linking tables how do I tackle them?

If there is an easier way of doing this than what I have thought could you please tell me :)

Links to resources or examples would be much appreciated. Thanks in advance

Thankyou

Take Care!


This is the query for your pseudocode:

SELECT
  procedure.*,
  patient.*,
  department.*,
  procedure_name.*,
  dosage.*
FROM
  procedure
INNER JOIN
  patient
ON
  patient.patient_id = procedure.patient_id
INNER JOIN
  department
ON
  department.department_id = procedure.department_id
INNER JOIN
  procedure_name
ON
  procedure_name.procedure_name_id = procedure.name_id
INNER JOIN
  dosage
ON
  dosage.dosage_id = procedure.dosage_id
WHERE
  procedure.procedure_id = ?

You can join any of your other tables exactly the same way. If you want rows back even if the table you're joining has no matching rows to the rows from the rest of the query, use a LEFT OUTER JOIN instead of an INNER JOIN. Where there are multiple rows matching the current rows (1:N/N:M) you will get as many rows as there are pairs in your result set.

If you need additional guidance/examples you'll have to be more clear about what you want to retrieve and what you don't understand.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜