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

  • Home
  • SEARCH
  • 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 1087895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:59:53+00:00 2026-05-16T22:59:53+00:00

I have a php function that dynamically queries a database, and returns 6 tables.

  • 0

I have a php function that dynamically queries a database, and returns 6 tables. I want to store each of these tables as a php array element, pass the array back via JSON/AJAX, and display each table as a seperate on a page. I wrote test code to do all of this. The test code takes an array of HTML strings and passes them back.

The problem I have is that in my test code, I used really simple strings:

$d1 = <<<END

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

END; 

$d2 = "<div id='#f-2'>Message 2</div>";

Actually, what I have is a whole bunch of php code to loop through SQL results and construct HTML tables:

while($row=pg_fetch_array($result, null, PGSQL_ASSOC))
  {

    if(!$written_header)
    {
      echo "<table class=\"fancy\" id=\"ticket_list_table\"><thead><tr><th>ID</th><th>Hardware Name</th><th>Serial No.</th><th>IP Address</th><th>Username</th><th>Password</th></tr></thead><tbody>";
      $written_header = true;
    }

    echo "<tr><td>",$row[id],"</td><td>",'$row[hardwarename]',"</td><td>",'$row[serialnumber]',"</td><td>",'$row[ipAddress]',"</td><td>",'$row[username]',"</td><td>",'$row[password]',"</td></tr>";  

  }

  pg_free_result($result);

  if($written_header)
  {
    // close the table body and table object
    echo "</tbody></table>";
  }
  else
  {
    echo "No results.";
  }
  echo "</div>";

How can I store this more complex stuff in a PHP variable so that I can then pass it back as an array element?

  • 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-16T22:59:54+00:00Added an answer on May 16, 2026 at 10:59 pm

    Not sure if understand you correctly, but

    $result = "<table>";
    $result .= "<tr>";
    $result .= "<trd>";
    

    This .= notation keeps adding new data to the end of previous value.

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

Sidebar

Related Questions

PHP: I have made up a function that returns an array. I would like
I have a PHP function that builds a JSON array via $jsonArray= array(); for
I have a PHP function that requires can take 3 parameteres... I want to
I have a PHP function that I want to make available publically on the
I'm trying to build a PHP function that allows me to have an array
I have a function that returns json (networks_function.php builds up some arrays and encodes
I have a page that is dynamically built by the database. For each thing
I have a PHP function that extract dat of an invoice from DB. The
I have a PHP function that takes a variable number of arguments (using func_num_args()
Is it possible to have a PHP function that is both recursive and anonymous?

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.