- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有 loan_id
的表,当我获取信息时,就可以了。这个问题是我需要点击 loan_id
号码,然后让它根据 id
号码显示结果。
<?php
$data = mysql_query("select * from request, users where request.user_id = users.id and request.user_id = $user_id") or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data )) {
Print "<tr class='my_loans_tr'>";
echo ("<td id='demo' onclick='myfunction(this) class='weblex-show- detail' data-toggle='modal' data-target='#myModalw'>" .$info['loan_id'] . "</td> ");
Print " <td class='admin_amount'>".$info['amount'] . "</td> ";
Print " <td class='admin_points'>".$info['points'] . "</td> ";
Print " <td class='admin_date'>".$info['req_date'] . " </td>";
Print " <td class='admin_status'>".$info['status'] . " </td>";
Print " <td class='admin_cancelled'>".$info['cancelled_loan'] . " </td></tr>";
Print "</tr>";
}
Print "</table>";
?>
数字146
147
是贷款ID,所以基本上我需要的是点击ID号,然后它会将ID号传递给我(我点击的任何数字)这样我就可以根据 loan_id
运行新查询。每个 loan_id
都有更多信息存储在另一个表中。我正在使用 Bootstrap 模式,如果这很重要的话。
我尝试了 JavaScript,但我最多只能提醒同一个 id:
<script type="text/javascript">
$(document).ready(function(){
$("#demo").click(function(){
alert("get content.");
});
});
</script>
最后我需要 php 中的值,以便我可以运行其他 MySQL 查询,
最佳答案
我不是 100% 确定你想要做什么,但我认为这就是你正在寻找的:
/functions/getUserRequest.php
这是一个清理请求的函数。最好在使用之前将其包含在页面上。这是可选的。
<?php
function getUserRequest($con,$user_id)
{
# Since mysql_ is deprecated/removed from new version, I will use PDO
# safely binding the value
$query = $con->prepare("select * from request, users where request.user_id = users.id and request.user_id = :0");
$query->execute(array(":0"=>$user_id));
while($result = $query->fetch(PDO::FETCH_ASSOC)) {
$row[] = $result;
}
return (isset($row))? $row : array();
}
/functions/connection.php
这是使用 define()
值作为连接凭据的数据库连接。这是可选的,但应该以更完整的方式实现。 mysql_*
在 PHP7 中被删除。
function connection()
{
return new \PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASS);
}
/index.php
# Here you would add a config with DB defines and such
# Add the functions
include_once(__DIR__.'/functions/connection.php');
include_once(__DIR__.'/functions/getUserRequest.php');
# Create connection
$con = connection();
?>
<table border="1" cellpadding="3">
<?php
# Since Ids are supposed to be unique, you should make an auto-incrementer
$i = 0;
# Pass id here
foreach(getUserRequest($con,123) as $info) {
?>
<tr class='my_loans_tr'>
<?php
/*
** Here is where the incrementing happens
** Also, pass the whole element to the js function
*/
?>
<td id='demo<?php echo $i ?>' onclick='myfunction(this)' class='weblex-show- detail' data-toggle='modal' data-target='#myModalw'><?php echo $info['loan_id'] ?></td>
<td class='admin_amount'><?php echo $info['amount'] ?></td>
<td class='admin_points'><?php echo $info['points'] ?></td>
<td class='admin_date'><?php echo $info['req_date'] ?></td>
<td class='admin_status'><?php echo $info['status'] ?></td>
<td class='admin_cancelled'><?php echo $info['cancelled_loan'] ?></td>
</tr>
<?php
$i++;
}
?>
</table>
然后你的 JS 函数就会启动:
<script type="text/javascript">
function myfunction(obj)
{
// This should get the value between the <td>Value</td>
var getValue = obj.innerHTML;
// You should then be able to use AJAX to retrieve data with
// inner value (or however you want to use this value)...
alert(getValue);
}
</script>
<小时/><小时/>
编辑:
由于您现在尝试使用 jQuery,因此您需要触发对类的点击,因为您的 id 都是唯一的。
<script type="text/javascript">
$(document).ready(function(){
// You need to be listening for the click on the class "detail"
$(".detail").click(function(){
// This captures the current selected DOM object
var obj = $(this);
// This will extract the value inside
var objValue = obj.text();
// This is where you send the data to a new page to get a response
$.ajax({
url: '/page/to/ajax/dispatcher.php',
type: 'post',
data: {
'id':objValue
},
success: function(response) {
// You can see the response in your console log
console.log(response);
// To update your html, you can just receive it from
// your ajax dispatch page and place it into the modal (or wherever)
$('#myModalw').html(response);
}
});
});
});
</script>
关于javascript - onclick在php上显示MySQL fetch echo的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41388994/
我有一个 HTML 文件,当您单击按钮时,Ajax 会加载一个 PHP 文件,然后 PHP 文件将一些文本回显到 HTML 文件。 问题是,如果我第二次(或第三次、第四次等)单击该按钮,下一个 ech
我正在尝试使用以下方法调用数据库中的 HTML/PHP 内容: 当调用该行时,HTML 会正确显示,但 PHP 不会。我相信这是主 echo 内部 echo 的原因。 Hello \
我正在尝试使用复选框来显示和更新 MySQL 数据库中的记录。我想根据复选框是选中还是未选中来更改复选框的值。但是我收到了这个错误: 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHIT
我遇到了重定向符号的不同位置( > , &2 message message echo message >&2 message >&2 echo message message 对于所有表单,我得到了
这个问题在这里已经有了答案: Source files in a bash script (2 个回答) 2年前关闭。 https://askubuntu.com/questions/250012/h
我注意到当我在 DOS 中使用 echo 将某些内容打印到文件时,会在字符串后附加一个空格。我需要打印没有尾随空格的字符串。有没有办法做到这一点,或者作为一种解决方法,从文件中删除尾随空格? 最佳答案
不确定我在这里做错了什么,但结果总是空的。只有当没有选择答案时,脚本才应该输出“你没有选择答案”,否则它应该输出给定的答案: 我已经按照提到的更新了脚本,但即使给出了答案,仍然得到空输出:/ 感谢到目
不确定我在这里做错了什么,但结果总是空的。只有当没有选择答案时,脚本才应该输出“你没有选择答案”,否则它应该输出给定的答案: 我已经按照提到的更新了脚本,但即使给出了答案,仍然得到空输出:/ 感谢到目
echo 'Welcome echo $_SESSION["username"];'; 在上面的代码中,它没有显示用户名变量。相反,它只是简单地回显 Welcome $_SESSION["userna
我试图在 php echo 语句中回显一个 php 变量。 我在 MySql 数据库中有一个名为 display_code 的列,其中包含一个值,例如 $num_rows_customers。 我从数
如上所述,我想知道为什么我们使用@Echo off/on 而不是Echo off/on。这是有什么原因还是只是为了可见性?根据这个,它在视觉上似乎没有什么不同: C:\Users\Jack> Echo
我希望能够将新的 ECHO 消息连接到先前的 ECHO 消息,如下所示: 命令: ECHO PROCESSING... REM some process here ECHO DONE 结果: PROC
我不了解 jQuery,所以如果这是一个愚蠢的问题,我很抱歉。 当我将值从 php 传递到 javascript 时,即使之前用 echo 打印的消息也被传递,我怎样才能避免这种情况? php $
请有人解释一下下面的结果差异 echo intval(1e10); 输出1410065408 echo 1e10; 输出10000000000 最佳答案 有符号整数有最大值。在 32 位系统上,它
我正在制作导航菜单,我想添加一个事件类这是我的代码 我想输出 CSTYLE 并使用 'if 来回显事件类 %s %s ', $row['CSTYLE'], $row['id'], $row['na
echo -n 的终端手册页如下: -n Do not print the trailing newline character. This may also be achie
直到今天它突然停止工作时,它一直工作得很好......(我知道这不是很有帮助,但我到处都看了看) 我正在遍历从 mySQL 查询返回的值,并将每个值放入一个数组中,然后将这个数组放入另一个数组中。然后
目前我正在这样做: $lines = file('data/index'); foreach ($lines as $value) list($title, $location) =
我在 PHP CLI 中运行以下脚本: 什么都没有显示。如何启用输出? 最佳答案 在您的终端中运行它: php -r 'echo "Hello World!\n";' 关于echo - 在 PHP
希望这是一个简单的问题... 我正在使用批处理文件来移动一些文件,不幸的是,出于各种原因,这有点复杂。要正常运行,需要右键单击并“以管理员身份运行”。 为了提醒未清洗的大众和我执行该步骤,我希望第一行
我是一名优秀的程序员,十分优秀!