如何在另一个页面上单击锚标记时,如何在php脚本中更改PHP变量?

时间:2015-07-02 21:51:20

标签: php jquery mysql search dynamic

所以我想要做的是有一个即时搜索供稿,它显示我的mysql数据库中的成员列表,当用户点击一个锚标记与行相关的内容时(li)我想要更改变量在另一个脚本中是点击的行的id。我将在下面提供我的脚本

的index.php

<script>
function searchUserQ(){
    var searchTxt = $("input[name='userSearch']").val();
    console.log(searchTxt);

    $.post("includes/search.php", {searchVal:searchTxt},
        function(output){
           $("#userResults").html(output);
        });
}

$("#userResults").on("click", "a.employee", function(e) {
    e.preventDefault();
    $("#editId").val($(this).data("id"));
});
</script>

<h1 class="editUser">Edit User</h1>
<form action="index.php" method="post">
    <input type="text" name="userSearch" id="userSearch" placeholder="Search For Employee By First Name" onkeyup="searchUserQ();" />
    <submit type="submit" />
</form>
<div id="userResults">

</div>
<form class="editUser" action="includes/uploadEmployee.php" method="post"   enctype="multipart/form-data">
    <input type="hidden" name="editId" id="editId">
</form>

此文件会在我的索引页面中创建搜索结果的即时列表,并且是构建锚标记的位置我想要更改变量

包括/ search.php中

<?php


$output .= "<li><div class='employeeSearch' style=\"background: url('$photo'); width: 75px; height: 75px\"></div><h6>" . $firstName  . "</h6>" . " " .  "<h6>" . $lastName . "</h6><a href='#' class='employee' data-id='$id'>Select Employee</a></li>";

  echo $output;

此文件用于在一切完成后更新数据库,现在它只更新第42行

包括/ uploadEmployee.php

 $selectedId = $_POST['editId'];

$sql = "UPDATE employees SET firstName = '$_POST[editUserFirstName]', lastName = '$_POST[editUserLastName]', password = '$_POST[editUserPW]', permission = '$permission', address = '$_POST[editUserAddress]', email = '$_POST[editUserEmail]', phone = '$_POST[editUserPhone]' WHERE id = $selectedId";

1 个答案:

答案 0 :(得分:1)

添加

QProgressBar* bar = new QProgressBar();
bar->setRange(0,0);

到表格。单击锚点时,它应将ID存储到此输入字段中。然后,更新脚本可以使用<input type="hidden" name="editId" id="editId"> 来获取应更新的行的ID。

您的主播可以这样写:

$_POST['editId']

您可以使用以下方法设置隐藏字段:

echo "<a href='#' class='employee' data-id='$id'>Select Employee</a>";