我正在嘗試使用php,而且我對它真的很陌生。爲每一行分配一個按鈕的值
我創建了一個頁面(使用php代碼)將信息發送到數據庫和一個顯示數據庫信息的頁面。
我的問題是:可以說我要輸入10個信息,但我只顯示5個信息,如何顯示其餘信息點擊每個按鈕的行?
我必須爲按鈕賦值嗎?我不明白我如何可以將按鈕關聯到該行。
基本上對於每一行我想顯示該特定行的信息的其餘部分點擊該特定按鈕。
任何幫助將appricciate。感謝
-----腳本,在數據庫中插入信息-----
<?php
$name = mysqli_real_escape_string($link, $_POST['name']);
$mail = mysqli_real_escape_string($link, $_POST['mail']);
$number = mysqli_real_escape_string($link, $_POST['number']);
$device = mysqli_real_escape_string($link, $_POST['device']);
$model = mysqli_real_escape_string($link, $_POST['model']);
$problem = mysqli_real_escape_string($link, $_POST['problem']);
$sql = "INSERT INTO cj (name, mail, number, device, model, problem) VALUES ('$name', '$mail', '$number', '$device', '$model', '$problem')";
$result = mysqli_query($link, $sql);
// if query fails stop script and echo error
if($result === false)
{echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
exit;
}
header("location:add-customer.php?message=A job and customer has been added to the database");
exit;
echo "You'll never see this";
?>
-----------頁面顯示信息---- -
<?php
$sql = "SELECT * from "database name"";
echo "
<table class='table'>
<thead>
<tr>";
/* Get field information for all columns */
echo "<form action='' method=post>";
echo "<tr class='info'>
<input type=hidden name=hidden value=" . $row['id'] . ">
<td>" . $row['id'] . "</td>
<td>" . $row['device'] . "</td>
<td>" . $row['model'] . "</td>
<td>" . $row['problem'] . "</td>
<td>
</td>
<td>
<a class='btn btn-primary btn-sm' data-toggle='modal' data-target='#myModal' value= " . $row['id'] . " > Info</a></form></td>
</tr>";
echo "</form>";
}
echo "
</tbody>
</table>";
?>
<div class="container">
<!-- Trigger the modal with a button -->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Customer Information</h4>
</div>
<div class="modal-body">
<?php
include("../includes/connection.php");
if ($link->connect_errno > 0) {
die('Unable to connect to database [' . $link->connect_error . ']');
}
$sql = "SELECT name,mail,number from databasename WHERE **???**;
if (!$result = $link->query($sql)) {
die('There was an error running the query [' . $link->error . ']');
}
echo "
<table class='table'>
<thead>
<tr>";
/* Get field information for all columns */
while ($finfo = $result->fetch_field()) {
echo "
<th>" . $finfo->name . "</th>";
}
echo "
</tr>
</thead>
<tbody>";
while ($row = $result->fetch_assoc()) {
echo "<tr class='info'>
<td>" . $row['name'] . "</td>
<td>" . $row['mail'] . "</td>
<td>" . $row['number'] . "</td>
</tr>";
...
那麼按鈕是否會將用戶帶到「詳細信息」頁面,在那裏他可以看到有關該行的更多信息,或者更像是「點擊」按鈕上顯示內容的「展開」按鈕? –
你需要顯示你的代碼,因爲我不知道在這個上下文中可量化的「信息」是什麼 –
@是按鈕正在彈出的模式彈出窗口,它顯示有關同一行的更多信息按鈕已被點擊。這就是爲什麼我認爲應該爲與例如行ID相同的按鈕分配一個值,但是我不確定 – MisterNubb