heyas,

ive been created a site menu which hopefully will be created based in whats in a myswl table of mine. The site menu was made using javascript and dhtml, im just wondering if its possible to embed some php code in the script?. I tried doing it myself but I have a feeling the server do not parse the php part of the script as php. Is there a knack to this or can it not be done?

Thanks

-Stew


    Not that I know of. However, I guess it might be possible if you're really good with JavaScript to somehow connect back to your DB (assuming the port is open for that as well as the web server) and then interact with the DB while the page is loaded using JS instead of PHP. The big downside is that you'd have to store your DB password in cleartext in the JS in the HTML file. I suppose if you made a MySQL user with strict enough permissions, it might not be as big a problem, but make sure you know what you're doing.

      just had a thought, perhaps I could get the php code to generate all of the javascript rather than the JS doing the php stuff within it.

        just a reminder, PHP is processed before anything else. the PHP is processed into plain HTML then the JavaScript works from then on. you can put JavaScript into PHP but you cannot put PHP into JavaScript

          3 years later

          Not completely true. :-) I've embedded PHP variables inside Javascript functions by concatenating the Javascript variable with the result of a <?= php statement. It works in sequence within the scope of the Javascript function in both (Apache) Windows and Linux environments.

            you do realise this post was about 3 years old right? An answer back then probably isnt applicable now (in saying that, I dont know how much PHP has changed since then heh)

              Write a Reply...