you cant mix php and javascript together like that. php happens (on the server) before the javascript is ever even created (on the client).
if you really must do it this way, you'll need to look into using something like the xmlHttpRequest object for javascript.
personally, unless you really must get this stuff from a db, i would just do the whole thing client side.