-3

I have this little piece of code in php. How can I make it a link or add a class to it to add style? I did this to my code:

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

Have I done something wrong? Has anyone idea what should I do? Thanks.

I also read this, but it didn't help.

Community
  • 1
  • 1
coolest
  • 677
  • 1
  • 6
  • 17
  • 3
    I'm not sure you understand how HTML markup works, you are putting a `` tag inside of a span? Also, You can't add styling to php, you add styling to HTML. - Where is your CSS? - Did you try and inspect your code to see if the link is there and it's CSS hiding it? – Epodax Aug 19 '16 at 07:42
  • Where do you want to add style or class, which design do you want to see? – Teymur Mardaliyer Lennon Aug 19 '16 at 07:51
  • I want to add style to categoria row so I put a class named tab to it. My css is in another file. I dont think its neccessary,because even the href tag doesnt work – coolest Aug 19 '16 at 07:52
  • 2
    Your HTML is invalid. The span will not style the table cell. Put the class on the TD and remove the span and the A on the content: `' . $row["categoria"] . ''; ?>` – mplungjan Aug 19 '16 at 07:54
  • First, don't write echo every time, you can easily add class="" or style="" attribute to any html element, and also write class name or inline style inside them. You didn't see link because your html structure was wrong, you wrote title outside of element, that is why you didn't sew link. Try to write your codes clearly it will help you to find problems easily. – Teymur Mardaliyer Lennon Aug 19 '16 at 08:05
  • @Doe what do you want to do? Where do you want to give a style can you tell us? I formatted your code below but I removed it, i think you couldn't catch it before I removed it. I will undelete it, but i will remove it again after few minutes. – Teymur Mardaliyer Lennon Aug 19 '16 at 09:23

2 Answers2

0

First, don't write echo every time, you can easily add class="" or style="" attribute to any html element, and also write class name or inline style inside them. You didn't see link because your html structure was wrong, you wrote <span><a>title</a></span> outside of <td> element, that is why you didn't sew link. Try to write your codes clearly it will help you to find problems easily.

<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>
0

This would be the right format of adding html classes inside php rows.echo '<td class="tab"><a href="#"><b>' . $row["marca"] . '</b></a></td>';

coolest
  • 677
  • 1
  • 6
  • 17