gaban gaban - 3 months ago 7
HTML Question

Creating new table which has connection with another table

I am trying to create new table called

Patients
which has relation only with single doctor. Since we do not know that Doctor has any patient or not I will implement every new table for every single doctor in PHP (I know it is not efficient but well!).

Doctor Table.php

After each patient click on the Doctor's table I have to go to the elated patient table and to print it as an html table. Should I create a big patient table and check something doctor related to pull the data or should i create tables for every single Doctors? BTW, every patient table will have added patient feature.

**THIS PART IS GOING TO Patient.PHP**
while($row = mysqli_fetch_assoc($result))
{ echo "<form action= 'Patients.php' method = 'POST'>";
echo"<tr>";
echo "<td>".$row[DoctorID]."</td>";
echo "<td>".$row[name]."</td>";
echo "<td>".$row[surname]."</td>";
echo"<td>".$row[specialityID]."</td>";
echo '<td><input class = button button2 type = submit name = Patients value = Patients /><td>';

echo "</tr>";

}
**THIS PART IS THE PATIENT TABLE WHICH ALREADY AN EXISTING TABLE IN MYSQL DATABASE**
$sql = "SELECT patientID,name,surname FROM Patients";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{ echo "<table>";
echo "<tr>";
echo "<th>PatientID</th>";
echo"<th>Patient Name</th>";
echo"<th>Patient Surname</th>";
echo"</tr>";
while($row = mysqli_fetch_assoc($result))
{ echo"<tr>";
echo "<td>".$row["patientID"]."</td>";
echo "<td>".$row["name"]."</td>";
echo "<td>".$row["surname"]."</td>";
echo "<td><input class = 'button button3' type='button' onclick = 'myFunction($row[patientID])' value = 'Düzenle'></td>";
echo "</tr>";

}

Answer

Should I create big patient table and check somthing doctor related to pull the data? Or should i create tables for every single Doctors.

Create one table that stores only the association between all doctors and all patients, and fields to describe that association. It might have fields

  • doctor ID (a primary key in your doctors' table)
  • patient ID (a primary key in your patients' table)
  • timeAdded (when the patent became associated with this doctor)
  • any other field that's about how one patient is linked to one doctor

The table should also have an INDEX UNIQUE(doctor ID, patient ID) to make sure that there is no duplicate doctor-patient link in the table.

This table is for all doctors and all patients. Very importantly, it does not store the doctors' or patients' info such as names or emails (that's for separate doctors and patients tables). The job of this table is to store only the associations, the links.

This design will allow you to easily fetch things which would be much harder if you had a separate patients table for each doctor. For instance:

  • Which doctor has the most patients?
  • Which doctor has added more patients in the last 6 months?
  • Which patients are linked to multiple doctors?
Comments