我有我的MySql DB
(其中包含客戶信息),我從中獲取數據,並在表格中顯示它們。我只在桌面上顯示客戶名稱。我希望能夠點擊一個按鈕,每個錶行內,然後顯示在特定行的附加信息可點擊的HTML表格包含數據能夠顯示更多數據onclick
代碼這裏:
function customers(){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "gymdb";
$p = '';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM company_customers WHERE company_id=" . $_SESSION['id'] . ";";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$p .= '
<hmtl>
<head>
</head>
<body>
<table class="container">
<thead>
<tr>
<th><h1>Name</h1></th>
<th><h1>Surname</h1></th>
<th><h1>More Info</h1></th>
</tr>
</thead>
';
while($row = $result->fetch_assoc()) {
$p .= '
<tbody>
<tr>
<td style="width:50%">' . $row['customer_name'] . '</td>
<td>' . $row['customer_surname'] . '</td>
<td style="width:100px" class=thisone onclick="show()"> +</td>
</tr>
</tbody>
<script>
</script>
</body>
</html>
';
}
} else {
}
$conn->close();
你有2個選擇:a)首先獲取信息並通過css隱藏它們並顯示它們onclick 2)使用ajax向你的php服務器和db請求發出一個新請求,然後將它加載到你的單元格中。你的show()函數在做什麼? –