【发布时间】:2015-05-02 01:43:35
【问题描述】:
我正在尝试这样做: 当用户单击包含来自 mysqli 的行的简要信息 div 时,将学生 id 发送到 id.php,然后 php 文件将通过学生 id 获取所有数据并将其回显,以便我可以使用 ajax 将其放入我原来的index.php
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
//in your Javascript, put
$(document).ready ( function () {
$("#briefinfo").click (function(){
$.ajax({
type: 'POST',
url: 'id.php',
var studentid = "<?php echo $studentid; ?>";
data: { id: studentid },
success: function(response) {
$("#briefinfo").html(response);
}
});
});
});
</script>
请帮忙。 这是id.php
<?php
// connect to the database
include('connect-db.php');
// confirm that the 'id' variable has been set
require_once("db.php");
$id = $_POST['id'];
if ($result = $mysqli->query("SELECT * FROM requests WHERE student_id=$id"))
{
if ($result->num_rows > 0)
{
echo "<table border='1' cellpadding='10'>";
echo "<tr><th>Document #</th><th>Student #</th>
<th>Documents needed</th><th>Edit</th><th>Delete</th>
<th>recorded comment</th><th>unverify</th><th>comment</th><th>payment amount</th><th>set payment</th>
</tr>";
while ($row = $result->fetch_object())
{
echo "<tr>";
echo "<td>" . $row->id . "</td>";
$studentid=$row->student_id;
echo "<td><a href='id.php?id=" . $row->student_id . "'>$studentid</a></td>";
echo "<td>" . $row->document . "</td>";
echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
echo "<td>" . $row->comment . "</td>";
echo "<td><a href='unverify.php?id=" . $row->id . "'>unverify</a></td>";
echo "<td><a href='comments.php?id=" . $row->id . "'>comment</a></td>";
echo "<td>" . $row->paymentamount . " pesos";"</td>";
echo "<td><a href='paymentamount.php?id=" . $row->id . "'>set amount</a></td>";
echo "</tr>";
}
echo"<br><br>";
echo "</table>";
}
else
{
echo "No results to display!";
}
}
else
{
echo "Error: " . $mysqli->error;
}
?>
【问题讨论】:
-
“内容”与什么有关?通常这将类似于 jQuery('yourdiv').html(response);
-
这基本上是个人资料。所以在#briefinfo 中,它有来自mysql 的学生ID、姓名等。我希望它在单击时显示更多数据(mysql 表中的每一行)。
标签: php jquery mysql ajax mysqli