Need some help getting my Javascript to work inside of some PHP.
This is the PHP that takes several values from a MySQL Database:
PHP Code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("fsdb", $con);
$result = mysql_query("SELECT *FROM test LIMIT 3");
while($row = mysql_fetch_array($result))
{
echo '<table width="600" border="0" cellpadding="1"><tr><th width="33%" bgcolor="#CCCCCC" scope="col">';
echo $row['Name'];
echo '</th>';
echo '<th width="33%" bgcolor="#CCCCCC" scope="col">';
echo $row['Artist'];
echo '</th>';
echo '<th width="33%" bgcolor="#CCCCCC" scope="col">';
echo 'Download';
echo '</tr>';
echo '</table>';
}
mysql_close($con);
?>
That all works fine but what I'm trying to do is take the Name and Artist and add them onto the end of a URL, which is where my piece of JS comes in:
Code:
<script type="text/javascript">
var name="$row['Name']";
var artist="$row['Artist']";
var search= name+" " +artist;
var link1='<a href="http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch?term=';
var link2='">Download</a>';
document.write(link1+search+link2);
</script>
As you can see I want the variables Name and Artist to take there values from the MySQL Database and then they would be added onto the end of the URL.
I think the reason I can't get it to work might be something to do with the quotes ?
Thanks 
|