Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help putting my JS inside PHP
Old 07-20-2009, 12:56 PM Help putting my JS inside PHP
jameswhite's Avatar
Average Talker

Posts: 15
Name: James White
Trades: 0
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
jameswhite is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-20-2009, 01:42 PM Re: Help putting my JS inside PHP
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
JavaScript doesn't know there is such a thing as PHP, therefore, the line:
Code:
var name="$row['Name']";
doesn't mean anything, since it would refer to a string containing "$row['Name']" literally.

All PHP executes before any of the client side code even shows up. Therefore, if you are going to assign any PHP variables to be JavaScript variables, you will need to echo them:
PHP Code:
<script>
var myVariable = "<?php echo $var;?>";
</script>
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 07-20-2009 at 01:45 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Help putting my JS inside PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33550 seconds with 12 queries