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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:03:24+00:00 2026-05-23T12:03:24+00:00

I have never programmed anything in php before and haven’t touched html in 10

  • 0

I have never programmed anything in php before and haven’t touched html in 10 years. I could use some help. I am querying a postgresql database using php. I am trying to display my query results in a table format with headers like this:

first_name   last_name   employee_id
tom          jones       111
bob          barker      112
bill         davis       113

Sample code I am trying to get to work correctly:

echo("<table border=2");
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
    foreach ($line as $col_value => $row_value) {
        echo("<tr><td>$col_value</td><td>$row_value</td></tr>\n");
    }
}
echo("</table>");

My formatting is being displayed like this:

first_name tom
last_name jones
employee_id 111
first_name bob
last_name barker
employee_id 112
first_name bill
last_name davis
employee_id 113

As you can see I am storing my query in an associative array.

Thanks for any help.

  • 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-05-23T12:03:24+00:00Added an answer on May 23, 2026 at 12:03 pm
    echo("<table border=2><tr><td>first_name</td><td>last_name</td><td>employee_id</td></tr>");
    while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
        echo("<tr>");
        foreach ($line as $col_value => $row_value) {
            echo("<td>$row_value</td>");
        }
        echo("</tr>\n");
    }
    echo("</table>");
    

    Or:

    echo("<table border=2><tr><td>first_name</td><td>last_name</td><td>employee_id</td></tr>");
    while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
        echo("<tr><td>".$line[0]."</td><td>".$line[1]."</td><td>".$line[2]."</td></tr>\n");
    }
    echo("</table>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never programmed in java or eclipse before, although I have used c# and
I have never programmed VB, but a university course forcibly requires me to use
I've never programmed a game, but have about a dozen years programming interfaces. After
I've never programmed a game, but have about a dozen years programming interfaces. After
I have never programmed a gadget for Vista or Seven, but I would like
Hey guys, before you guys say anything I have searched and can not find
I've never programmed before and am having difficulty getting link_to to render the corresponding
First, I must say have never programmed in iOS, I am only familiar with
I have never done profiling. Yesterday I programmed a ProfilingTimer class with a static
I am a beginner programmer that have never used anything other than what's included

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.