我可以使用php从数据库中获取我的表的所有内容。 如何在表格的一列中添加按钮,或者在选择或复选框等其他组件中添加按钮....
我张贴了一张照片,以便更清楚。 我使用php获取表,但如何在行中插入组件?
$db = new mysqli("...", "...", "...", "...");
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT * from ...";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->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['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['mail'] . "</td>
<td>" . $row['number'] . "</td>
<td>" . $row['device'] . "</td>
<td>" . $row['price'] . "</td>
<td>" . $row['paymenttype'] . "</td>
<td>" . $row['status'] . "</td>
<td> add </td>
</tr>";
}
echo "
</tbody>
</table>";
?>
-----------------更新
echo "<tr class='info'>
<td>" . $row['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['mail'] . "</td>
<td>" . $row['number'] . "</td>
<td>" . $row['device'] . "</td>
<td>" . $row['price'] . "</td>
<td>" . $row['paymenttype'] . "</td>
<td>" . $row['status'] . "</td>
<td><input type='checkbox'></td>
<td><a href='http://yourlink' >delete</a></td>
</tr>";
答案 0 :(得分:1)
<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['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['mail'] . "</td>
<td>" . $row['number'] . "</td>
<td>" . $row['device'] . "</td>
<td>" . $row['price'] . "</td>
<td>" . $row['paymenttype'] . "</td>
<td>" . $row['status'] . "</td>
<td> <button class='btn' >Button</button> </td>
</tr>";
}
echo "
</tbody>
</table>";
?>
答案 1 :(得分:1)
找到了这个解决方案
<td><a class='btn btn-primary btn-lg' href='send.php?name=".$row['name']."'>Send</a></td>