Jump to content

[SOLVED] mixing PHP in JS?


galvin

Recommended Posts

Just curious if this is possible (don't want to try and write the code if it's not even possible).

 

My basic question is…Can you mix PHP inside Javascript?  For example, I am going to have a database (mySQL) with list items in it and I'm going to query all the list items using PHP/MySQL and then I want to use the result of the query to populate a Javascript array. 

 

So for example, if my php/mysql query brings back 5 list items...

 

monkey

cat

frog

shark

llama

 

I’d like to then populate those values into a Javascript array.  So Javascript wise, I’d start with an empty array like…

 

var randomAnimals=new Array();

 

And then I’d want to take those list items retrieved from the database via php/mysql and somehow loop through them and populate them into the JS array and ultimately end up with…

 

var randomAnimals=new Array(“monkey”, “cat”, “frog”, “shark”, “llama”);

 

If it is possible, I think I should be able to write the code.  Again, just want to make sure it's doable to essentially mix PHP in Javascript. (and sorry if this should be in the JS section, rather than PHP.  I couldn’t decide so I put it in the PHP section)

 

Link to comment
https://forums.phpfreaks.com/topic/157088-solved-mixing-php-in-js/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.