PHP如何在弹出模式中获取用户ID(变量) [英] PHP How to get userID (variable) in pop up modal

查看:90
本文介绍了PHP如何在弹出模式中获取用户ID(变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多员工及其信息显示在页面上.通过数据库检索员工的信息,然后使用foreach()循环显示符合搜索条件的所有员工,示例可以在下面的图片中看到

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

现在,当用户单击按钮时,将触发带有一些基本表单字段的简单Bootstrap弹出模式.从下面的示例图片中可以看到

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

我的问题

单击按钮以使用/处理模式数据时,我需要获取$userID.

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

我尝试过的事情

我曾尝试使用<a>元素将具有用户ID的参数绑定到该元素,如下所示:

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.

然后,我尝试对#c3>属性使用#号,然后将参数$userID出价给它,如下所示:

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.

结论

我希望这个问题是有道理的,我几乎没有想法,也不知道如何进一步解决这个问题.

I hope this question makes sense, I'm pretty much out of ideas, no idea how to further approach this problem.

推荐答案

您将用户ID添加到锚标记中.要获取属性data-id的内容,您必须使用

You add the user-id in the anchor tag.To get the contents of the attribute data-id you have to use

<a id="myid" data-id="123">link</a>
<script>
  $('#myid').data("id");
</script>

这篇关于PHP如何在弹出模式中获取用户ID(变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆