Ok I understand now and I have done something similar. This may not look pretty but it does work well.
$acsql="select positionid, accessname from positions p, access a where a.accessid=p.access";
It wouldn't be too hard to adapt to what you need. As for the actual code to make it work I have this.
Of course some of that specifically applys to my script and it is setup in oop so it isn't procedural but you should get the idea. As is it won't work without some minor adjustments but that does what you need it to
var position=new Array();
<?= fetch_options(); ?>