首页 > 解决方案 > 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>";
      }                                                                   
 ?>

标签: phphtml

解决方案


你可以这样做:

<?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; ?>

推荐阅读