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 8710533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:39:00+00:00 2026-06-13T04:39:00+00:00

I am generating a table in HTML from a MySQL database, so that stored

  • 0

I am generating a table in HTML from a MySQL database, so that stored data can be displayed on a web page, and ultimately downloaded as a spread sheet.

I have a large set of SQL headers (probably the wrong name for this), that is to say the ‘Title’ of any given column.

I am using SELECT to get the data from MySQL via PDO:

           $sql ="
             SELECT     
            `sv_20`  AS `Name`,
            `sv_21`  AS `Age`,
            `sv_22`  AS `Height`,
            `sv_23`  AS `Weight`,
            ...
            ...
            `sv_999`  AS `Something`

        FROM 
            database.table";

In PHP I would define two arrays (the database headers and the titles I’d like them to have) and then write a foreach loop saying:

 foreach(array_combine($headers, $titles) as $header => $title)
 {
 echo "`$header`  AS `$title`,";
 }

Which would give me the complete set of calls, is there a way to do this in SQL when querying a database? Thank you

  • 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-13T04:39:01+00:00Added an answer on June 13, 2026 at 4:39 am

    It’s basic string manipulation, instead of echo, you want to append this to the string with $sql .=

    You’ll have some problems with the extra comma after the last item, it’s better to

    $sql = array();
    foreach(....)
        $sql[] = "`$header`  AS `$title`";
    

    and then do a join(',', $sql);

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

Sidebar

Related Questions

So I have this simple PHP loop that is generating html table data with
I have an ASP.NET page and I am generating an HTML table in my
I have an MVC application view that is generating quite a large HTML table
I have generated a html table from my web application and save the table
I have a table in HTML which I am generating from XML/XSL and I
I want to auto-generate a HTML table from some custom data. One of the
Can you recommend a declarative table-generation taglib for JSP (with EL) that is still
I have a table displaying results from a database, and I am adding some
Is it possible to transpose an html table (without javascript). I m generating a
I'm generating PDFs from HTML (using ABCPdf and C#) and the files are coming

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.