A number of employees and their info gets shown on a page. The info of employees gets retrieved via a DB and then a foreach()
loop is used to display all employees who fit the search criteria, an example can be seen on image below
Now when the user clicks the button, a simple Bootstrap pop up modal gets triggered, with some basic form fields. As can be seen from example image below
My Problem
I need to get the $userID
when a button is clicked to work with / process data in modal.
Below is an extract of relevant code:
$teacherClass = new TeacherSearch();
$teachers = $teacherClass->showAllTeachers();
if (is_array($teachers)) {
foreach ($teachers as $teacher) {
$src = $teacher['userID'];
<div class="teacher-info">
<p class="teacherLabel">
NAME:
<?php
echo $teacher['name'];
?>
</p>
<p class="teacherLabel">
HEADLINE:
<?php
echo $teacher['headline'];
?>
<p class="teacherLabel">
LOCATION:
<?php
echo $teacher['location']
?>
</p>
<!--BUTTON GOES HERE-->
}//foreach
What I've tried
Ive tried using an <a>
element binding a parameter with userID to it, like so:
<a href="body.php?teacher='<?php echo $teacher['userID'] ?>'" data-target="#myModal">Hire <?php echo $teacher['name'] ?></a>
As is to be expected the following triggered a new page reload inside the modal.
I then tried using a # sign for ahref
attribute and then biding parameter $userID
to it like so:
<a href="#?teacher='<?php echo $teacher['userID'] ?>'"></a>
The above lead to an undefined index error as can be seen in the picture above.
Conclusion
I hope this question makes sense, I'm pretty much out of ideas, no idea how to further approach this problem.