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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.