php - how to add an html button do each row in a table filled with php data?
问题描述
I'm trying to add an edit button to this table, the table is in html as is the button, the data is been taken out of phpmyadmin. The error i get is: syntax error, unexpected token "class", expecting "," or ";" in the line before $valor[accID]. This is my code:
<?php
$data = array();
$data = popularCustomerTable();
foreach($data AS $row => $valor){
echo "<tr>
<td> "<a class= "address-book-edit btn--e-transparent-platinum-b-2"; href="dashboard-customer-edit.php">Edit</a> "</td>
<td>".$valor["accID"]."</td>
<td>".$valor["cusName"]."</td>
<td>".$valor["cusEmail"]."</td>
<td>".$valor["cPass"]."</td>
<td>".$valor["cPhone"]."</td>
<td>".$valor["cusMailAddress"]."</td>
<td>".$valor["cusBillAddress"]."</td>
<td>".$valor["cusCity"]."</td>
<td>".$valor["cusSate"]."</td>
<td>".$valor["cusCountry"]."</td>
<td>".$valor["cusZipCode"]."</td>
<td>".$valor["cusStatus"]."</td>
</tr>";
}
?>
解决方案
你可以这样做:
<?php
$data = array();
$data = popularCustomerTable();
foreach($data AS $row => $valor):
?>
<tr>
<td>
<a class= "address-book-edit btn--e-transparent-platinum-b-2"
href="dashboard-customer-edit.php?id=<?php echo $valor["accID"]; ?>">Edit
</a>
</td> <!-- I added a an ID identifier to the link -->
<td>"<?php echo $valor["accID"] ?>"</td>
<td>"<?php echo $valor["cusName"] ?>"</td>
<td>"<?php echo $valor["cusEmail"] ?>"</td>
<td>"<?= $valor["cPhone"] ?>"</td> <!-- Or use this way-->
....
</tr>"
<?php endforeach; ?>
推荐阅读
- java - 获取项目计数中回收器视图适配器中的空指针 expetion
- java - 由于未经验证的 URL 参数,Spring Boot 不明确的处理程序错误
- sql - Oracle 过程分页带来比预期更多的行
- azure-data-factory - Databricks 和 Polybase 无法解析包含多边形的 CSV
- javascript - Javascript:网络工作者中的无限循环
- javascript - 未处理的运行时错误类型错误:传播不可迭代实例的无效尝试
- dataframe - 基于值过滤并在火花数据框中创建列表
- grafana - 在 Grafana 仪表板中嵌入网站
- python - 使用 for 循环和 2d numpy 数组,有没有办法进一步减少数据?
- python - OpenCV set() 和 read() 函数太慢(Python)