Jump to content

[SOLVED] PHP and Javascript


Chevy

Recommended Posts

Hmmm...how to ask this.

 

This is my array in my javascript:

 

var menu2=new Array()
menu2[0]='<a href="http://www.test.com/inventory.php?act=play&id=$item[id]">Play</a>'
menu2[1]='<a href="http://www.test.com/inventory.php?act=feed&id=$item[id]">Feed</a>'
menu2[2]='<a href="http://www.test.com/inventory.php?act=equipt&id=$item[id]">Equipt</a>

 

 

Now when it displays on the page, the link looks like this "http://www.test.com/inventory.php?act=play&id=$item[id]"

 

I want it to be like: "http://www.test.com/inventory.php?act=play&id=1"

 

$item['id'] is defined, so I do not know what the problem is?

Link to comment
Share on other sites

Well.. um, are you actually outputting that code with PHP or what are you doing with it? PHP wont magically replace your variables outside PHP mode. You need to somehow get PHP to output the strings.

 

What you could do for example is have:

 

<?php
echo <<<TEXT
var menu2=new Array()
menu2[0]='<a href="http://www.test.com/inventory.php?act=play&id=$item[id]">Play</a>'
menu2[1]='<a href="http://www.test.com/inventory.php?act=feed&id=$item[id]">Feed</a>'
menu2[2]='<a href="http://www.test.com/inventory.php?act=equipt&id=$item[id]">Equipt</a>'
TEXT;
?>

Link to comment
Share on other sites

Now I have a question...since this is in a while loop now, it is just taking the highest value.

 

           

while ($item = mysql_fetch_array($item_select)){

                echo <<<TEXT
<script>
var menu2=new Array()
menu2[0]='<a href="http://www.test.com/inventory.php?act=play&id=$item[id]">Play</a>'
menu2[1]='<a href="http://www.test.com/inventory.php?act=feed&id=$item[id]">Feed</a>'
menu2[2]='<a href="http://www.test.com/inventory.php?act=equipt&id=$item[id]">Equipt</a>'
</script>
TEXT;

}

 

Say my highest value is 4.then every link I click will look like this

 

http://www.test.com/inventory.php?act=play&id=4

http://www.test.com/inventory.php?act=play&id=4

http://www.test.com/inventory.php?act=play&id=4

http://www.test.com/inventory.php?act=play&id=4

 

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.