无法向 php 添加样式

Cant add style to php

我在 php 中有这段代码。如何使它成为 link 或添加 class 以添加样式?我对我的代码做了这个:

<?php 
    <span class="tab"><a href="#"> 
      <?php echo "<td>" . $row["categoria"] . "</td>"; ?></a>
    </span>
?>

我是不是做错了什么?有谁知道我该怎么办?谢谢。

我也看了this,但没有帮助。

首先,不要每次都写echo,可以随便给任何htmlelement加上class=""style=""属性,也可以写[=14] =] 或 inline style 在里面。你没有看到 link 因为你的 html 结构是错误的,你在 <td> 元素之外写了 <span><a>title</a></span>,这就是你没有缝合 link 的原因. 尽量写清楚你的代码,这将有助于你更容易地发现问题。

<table>
    <?php 
      $sql="SELECT * FROM presta_prova " ; 
      $result=mysqli_query($con,$sql);    
      while($row=mysqli_fetch_array($result)) { 
    ?>
        <tr>
            <td><?php echo $row[ "marca"];?></td> 
            <td>
                <span class="tab">
                    <a href="#"><?php echo $row["categoria"];?></a>
                </span>
            </td>
           <td><?php echo $row[ "descrizione"];?></td>
         </tr> 
      <?php 
      } 
      ?> 
      </table>

这将是在 php 行内添加 html 类 的正确格式。echo '<td class="tab"><a href="#"><b>' . $row["marca"] . '</b></a></td>';