Jump to content

How to add some php in a simple script?


jeffstyle

Recommended Posts

Hi,I'm working on something where I want to use the window.open method to open a new window with content, depending on what's being read in a database.The entire code is like this:

<?php$showmusic = mysql_query("SELECT * FROM music ORDER BY datecode ASC");while($musicitem = mysql_fetch_array($musicagenda)) {?><BR /><DIV style="border:2px solid #770000; width:590px"><script language="JavaScript1.2">function track1(){window.open("player.php?track=<?php echo $musicitem['track']; ?>",	"musicplayer","location=0,toolbar=0,menubar=0,directories=0,resizable=0,status=0,scrollbars=0,width=400,height=100");}</SCRIPT><A href="java script: track1()"><?php echo $musicitem['title']; ?></A></DIV><?php}?>

In the end I want this piece of code to read everything in a table, and make the link in the script for each of the results found. The link has to change for every link.The problem here is this line:

window.open("player.php?track=<?php echo $musicitem['track']; ?>",

My editor (Rapid PHP 2010) also fails at color coding the php part.It probably has something to do with usage of " and ' but I'm not very good at JS so I have no clue how to fix this.Does anyone here have an idea how I can get this to work?Thanks!!

Link to comment
Share on other sites

There's nothing wrong with the PHP part. Just because your editor doesn't recognise it doesn't mean it won't work :). Remember that PHP and JavaScript are executed at different times, anyway, so nothing in the JavaScript could interfere with the PHP code.Do note you're overwriting the JavaScript function track1() lots of times - you need to call every function something different, or pass the track value via a parameter instead.Also, you'll want to use the type attribute for the JavaScript block (type="text/javascript"), instead of language.

Link to comment
Share on other sites

Ahh yes, you're so right about the track1() function.I forgot to change that also to.. well.. something coming from the database which is always random :)I'll also change the language thing, this is just something I found on a website.Thanks a lot for your help!

Link to comment
Share on other sites

Hmm.. well the javascript did come through and it seems it does use the stuff it's getting from the database. The function name is now also coming from the database and is always unique.But it seems I've killed it at the same time.This is the code from the source on the website, after php has been parsed:

<DIV style="border:2px solid #770000; width:590px"><script type="text/javascript">function 20110110(){window.open("player.php?track=January 2011 Mix.mp3",	"music","location=0,toolbar=0,menubar=0,directories=0,resizable=0,status=0,scrollbars=0,width=400,height=100");}</SCRIPT><TABLE width="590" cellspacing="0" cellpading="0">	<TR>		<TD width="*" bgcolor="#770000" align="left">		<FONT>		<B>January 2011 Mix</B>		</FONT>		</TD>		<TD widht="125" bgcolor="#770000" align="right">		<FONT>		<B>10-01-2011</B>		</FONT>		</TD>	</TR>	<TR>		<TD width="*" colspan="2">		<FONT>		<B>Genre:</B> House<BR />		<A href="java script: 20110110()">Listen</A>		</FONT>		</TD>	</TR></TABLE></DIV>

Everything seems fine, the "Listen" link does show, on mouseover, the bar below in the browser shows javascript 20110110()But when I click it, absolutely nothing happends. I currently have only this entry in the database for testing purpose, so it's not messing up with other functions.Any idea's?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...