Display Php Array result in an Html table

You’re close:

</thead>
<tbody>
<?php 
    foreach ($URLS as $URL){
        echo'<tr>'; 
        echo'<td>'. $URL['VideoTITLE']."</td>";
        echo'<td>'. $URL['GroupName'].'</td>';
        echo'<td>'. $URL['ByArtist'].'</td>';
        echo'<tr>';
    }
?>
</tbody>

Since you’re taking the values of the $URLS array and calling each one $URL you need to refer to $URL for each row’s value. Not the $row variable you originally used to populate the array from the database results.

FYI, you may want to look into htmlentities() to escape your data to help prevent XSS attacks.

Leave a Comment