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
https://forums.phpfreaks.com/topic/50538-php-query-insdie-a-java-script/
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.

 

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.

Archived

This topic is now archived and is closed to further replies.

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