Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:04:00+00:00 2026-06-16T02:04:00+00:00

I was trying to display an array in php to an HTML table but

  • 0

I was trying to display an array in php to an HTML table but there’s an issue. I found several examples here in stack overflow, but they don’t work for my case.

Controller:

<?php include('inc/db_connect.php');?>

<?php
try
{
  $sql = "SELECT id GroupName, VideoTITLE, ByArtist FROM videoclip";
  $result = $pdo->query($sql);
}
catch(PDOException $e)
{
  $error = 'unable to fetch data: '.$e->getMessage();
  include'error.html.php';
  exit();
}
$URLS = array();
while ($row = $result->fetch())
{
  $URLS[] = array('id' => $row['id'], 'GroupName' => $row['GroupName'], 'VideoTITLE' => $row['VideoTITLE'], 'ByArtist'=> $row['ByArtist'] );
}

html:

<div id="table_admin" class="span7">
        <h3>Videoclip List</h3>

        <table class="table table-striped table-condensed">

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

        </table>

    </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:04:01+00:00Added an answer on June 16, 2026 at 2:04 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have an array display information inputted from a PHP-created HTML form.
I have two issues:- Issue No :1 (PHP related) I can't display an array
I am trying to display a table in php. I have established a valid
I am trying to display from a MySQL Database using PHP and Ajax but
I'm trying to display an array of postcodes onto a google map using PHP
I am just trying to display a list from an array that I have
I'm trying to create an array to display the last 5 products a customer
I am trying to format an array of numbers to display in an array
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I'm trying to use a php function within a template html form that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.