Jump to content

PHP query insdie a java script


Recommended Posts

Here is the code I am trying to make work.  However it kills the javascript all together.

 

//Contents for menu 5

var menu5=new Array()

<?

$linksx=mysql_query("SELECT * FROM links ORDER BY title");

while($links=mysql_fetch_array($linksx)) {

$link_title = stripslashes($links['title']);

?>

menu5[<?=$links['link_id']?>]='<a href="<?=$links['link']?>"><?=$link_title?></a>

<? } ?>

 

Here is how the hardcoded menu 2 looks.

 

//Contents for menu 2

var menu2=new Array()

menu2[0]='<a href="?page=agentprofiles">Panic Agents</a>'

menu2[1]='<a href="?page=newprofile">New Agent Profile</a>'

menu2[2]='<a href="?page=editprofile">Edit Agent Profile</a>'

 

any insite you could give me would be very useful.

Link to comment
Share on other sites

yea im new to javascript and i tried something similar, even a very simple php code inside of the script tags and the entire javascript disappears. I dont think this can be done like this.

 

maybe this would work.

<script language='javascript'>

var menu5=new Array()

</script> 

<?

$linksx=mysql_query("SELECT * FROM links ORDER BY title");

while($links=mysql_fetch_array($linksx)) {

$link_title = stripslashes($links['title']);

?>

<script language="javascript" >menu5[</script> <?=$links['link_id']?><script language="javascript" >]='<a href="</script> <?=$links['link']?><script language="javascript> "></script> <?=$link_title?>[/url]

<? } ?>

 

so basically keep php and javascript as two different entities execute outside of one another.

 

so probably you have to manipulate like that.

 

 

check it out.

 

Link to comment
Share on other sites

The php shouldn't give you any issue with the Javascript since it's processed in the server (the browser sees the output only).

 

Run the script and view the source, make sure the output of your script is correct. For example, do you close your single quote after you close your anchor tag?

 

You can post the output here if you need anymore help.

please use [ code ] for your code.

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.