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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:47:22+00:00 2026-06-08T16:47:22+00:00

I have a Postgresql database on the server side. I’d like to load data

  • 0

I have a Postgresql database on the server side. I’d like to load data on it for display on a HTML webpage. How would I go about being able to get access to this data in javascript? Are there any tutorials out there? It seems like this would be a common thing to have done but so far I can’t seem to find out how to do it. I did find some stackoverflow questions about using php and node.js to do it but I can’t seem to get that working. php seems to be like the easiest way to do it, and I copied some code from another question, but it doesn’t seem to work.

    var patientData = [];
    var patient_id = 8;

    <?php
            $connection = pg_connect("connectstuff");

            if(!$connection)
            {
                    pg_close($connection);
            }

            $result = pg_query($connection, "query");
            if (!$result) 
            {
                    exit;
            }

            $row = pg_fetch_row($result, 0);

            echo "patientdata = $row;";
            echo "alert('asdf')";
    ?>

The alert isn’t even getting shown, so I don’t think the php code is even running.

  • 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-08T16:47:23+00:00Added an answer on June 8, 2026 at 4:47 pm

    Check the source of the generated page, and make sure that the $row value you’re outputting is actual syntatically valid javascript. E.g. if it’s an array representing a row of data, php will actually output Array, not some value from that row.

    beyond that, when using PHP to dynamically built javascript, you should ALWAYS use json_encode() to ensure that the PHP variables you’re inserting into the javascript come out as valid javascript. The slightest little syntax error in the inserted data will kill the entire JS code block, and you’ll end up where you are now – a dysfunctional page and no idea why it died:

    patientdata = <?php echo json_encode($row) ?>;
    

    will 100% guarantee that whatever you’re inserting into the JS code will NOT cause a parser error. Whether the data will actually work with your code is another matter, but at least the script won’t get killed at the parsing stage.

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

Sidebar

Related Questions

If I have a server with a database of top secret data in PostgreSQL
I have an application server which connects to a database server. I would like
I have a large readonly Wordnet PostgreSQL database that I'd like to use from
We do have a small data warehouse in PostgreSQL database and I have to
i have some functionality i'd like to get from the server-side code into the
I currently have 2000 records in a postgresql database being updated every minute that
Hy guys, i have a postgresql 8.3 server with many database. Actually, im planning
I would like to create a web application using PostgreSQL as a database. I
I have a postgresql database which contains multidimensional data. What I did was I
We have a dedicated database server that runs PostgreSQL 8.3 on linux debian. The

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.