I have a main table page that loads the results of a query with a menu at the side (or rather a collection of buttons). My problem is that when I load a modal from the table I only see the "id" from one of the records and it doesn't dynamically call the ID of the row.
Table:
Patient_ID | Patient | Presenting complaint ------------------------------------------- 23 | Dave | Injured wing 231 | Steve | Broken Leg This table populates on the admissions.php page and the row of buttons is within a cell in each row. What i want to be able to do, is load a modal with the admission_patient_id so that i can use it in a form. the form is in the add_carenote.php which is contained within a modal
Admissions.php
//Loop from admissions table $stmt = $conn->prepare("SELECT *FROM rescue_admissions INNER JOIN rescue_patientsON rescue_admissions.patient_id = rescue_patients.patient_id WHERE rescue_patients.centre_id = :centre_id AND rescue_admissions.disposition = 'Held in captivity' ORDER by 'admission_location' ASC"); $stmt->bindParam(':centre_id', $centre_id, PDO::PARAM_INT); // initialise an array for the results $applicants = array(); $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $admission_id = $row["admission_id"]; $admission_patient_id = $row["patient_id"]; $admission_date = $row["admission_date"]; $admission_name = $row["name"]; $admission_presenting_complaint = $row["presenting_complaint"]; $admission_date = $row["admission_date"]; $adm_format_date = new DateTime($admission_date); $adm_format_date = $adm_format_date->format('d-m-Y <\b\r> H:i'); print '<tr> <td>' . $adm_format_date . '</td> <td class="align-middle"><b>' . $admission_name . ' <BR></td> <td class="align-middle">' . $admission_presenting_complaint . '</td> <td class="align-middle"> <!-- icon button group --> <div class="btn-group" > <a href="https://rescuecentre.org.uk/view-patient/?patient_id=' . $admission_patient_id . '" type="button" class="btn btn-success" data-toggle="tooltip" data-placement="top" title="Manage Patient Record"><i class="fas fa-file" ></i></a> <button type="button" class="btn btn-primary" data-toggle="modal" data target="#carenotesModal"></button> <button type="button" class="btn btn-info" data-toggle="modal" data-placement="top" title="Medication Given"><i class="fas fa-syringe" ></i></button> <button type="button" class="btn btn-primary" data-toggle="modal" data- target="#carenotesModal-'. $admission_patient_id .'"> Add Note </button> </td>';?> This is the modal text in add_carenote.php
<div class="modal fade" id="carenotesModal" tabindex="-1" role="dialog" aria-labelledby="carenotesModal" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h4 class="font-weight-bold text-primary">Add a care note</h4> - <?php echo $admission_patient_id ?> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span></button></div> <div class="modal-body"> <form action="" method="post"> <p><label for="new_note">Enter your note below:</label></p> <textarea id="new_note" name="new_note" rows="4" cols="50"></textarea> <p><BR> Make this note public? <select id="public" name="public"> <option selected="selected">No</option> <option>Yes</option> </select></td> <input type="submit" id="submit" name="form1" value="Add Care Note" class="form_submit"> <input type="hidden" name="patient_id" value= "/// HERE is where ill need the variable "> </form> </div> I have seen a number of posts on here trying to achieve the same end result in passing the variable across. Ideally i want the "patient_id" from the row to populate the modal so that I can ensure the form goes to the correct patient record. I would like it as a popup so the user does not have to leave the admissions page.
Some of the solutions i have read either completely bricked my pages so the page didn't work or the modal didn't load at all. Some solutions used (i think ajax/jquery - scripts) but i wonder if a form/POST might be better?
it doesn't dynamically call the ID of the row....well, have you written any code which you expect to be doing that job? If you have, you don't seem to have shared it with us here. And if you had an attempt which didn't work, did you try to debug it? Maybe it just needs some tweaks. That would be better than us starting all over again from scratch. See also How to Ask and how to make a minimal reproducible example of your problem.data-idattribute on the specific link which was clicked, so that it populates dynamically based on the clicked link, rather than (as your code is now) hard-coded by PHP when the page was initially loaded. So all you have to do to use that example is amend the PHP code which outputs your modal-opening links so it includes the relevant data attribute in each link that it generates.