OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I transfer the PHP variables to another javascript file?

  • Thread starter Thread starter RephaelC
  • Start date Start date
R

RephaelC

Guest
So my goal is to use PHP to get data from a PostGreSQL database. I want to use this data in a separate javascript file so I can display it on the screen a certain way that I have my website configured. All the tutorials that I have seen online just puts a script tag inside the PHP file but I cannot do that because my website display javascript code is in the separate file. I just need the numbers to be in the javascript file that I got from the PHP file that got its data from the PostGreSQL database. How can I do this?

I just need help with the means to get to the ends because I have researched on my own but it is always not exactly what I want.

PHP:

Code:
<?php
$myPDO = new PDO('pgsql:host=myHost; dbname=myDBName', 'myUsername', 'myPassword');
?>

$result = $myPDO->query("SELECT * FROM table WHERE id = 'someID'");

Now I want to use this row's values in another javascript file. How can I do this?

<p>So my goal is to use PHP to get data from a PostGreSQL database. I want to use this data in a <em>separate</em> javascript file so I can display it on the screen a certain way that I have my website configured. All the tutorials that I have seen online just puts a script tag inside the PHP file but I cannot do that because my website display javascript code is in the separate file. I just need the numbers to be in the javascript file that I got from the PHP file that got its data from the PostGreSQL database. How can I do this?</p>

<p>I just need help with the means to get to the ends because I have researched on my own but it is always not exactly what I want. </p>

<p>PHP:</p>

<pre><code><?php
$myPDO = new PDO('pgsql:host=myHost; dbname=myDBName', 'myUsername', 'myPassword');
?>

$result = $myPDO->query("SELECT * FROM table WHERE id = 'someID'");
</code></pre>

<p>Now I want to use this row's values in another javascript file. How can I do this?</p>
 

Latest posts

Top