liamloveslearning Posted May 22, 2011 Share Posted May 22, 2011 Hi, Im working with an existing site for a friend at the moment and I've come across a bit of a problem, I need to pass an array value to a javascript file which I'm unsure of how to do, my php is... $rs = mysql_query("select users.id, twitterUser, coff from users where twitterUser != '' and users.id IN (select concat_ws(',', id) from users where id != ".$usersClass->userID().") and users.id NOT IN (select concat_ws(',', followedID) from activity where followerID = '".$usersClass->userID()."') and users.id NOT IN (select concat_ws(',', userid) from featured) ORDER BY credits DESC;") or die(mysql_error()); $nr = @mysql_num_rows($rs); if($nr != 0) { while($row=@mysql_fetch_object($rs)) { $divLeft = '<div class="user-box"><div class="twithandlepic"><img src="http://api.twitter.com/1/users/profile_image/'; $divRight = '<div class="twithandle">'; $clearDiv = '<div style="clear:both;"></div>'; print $divLeft.strip_tags($row->twitterUser)."?size=normal\"/><br \/>".$row->twitterUser.$divRight."<a href='javascript:void(0);' id='vote_$row->id' class='getPoint'>Get " .$row->coff. " credit(s)</a><br /></div>$clearDiv</div></div>"; } Now I have a function in my javascript which is carried out after an onClick event... newbalance = newbalance+1; What I need to do is somehow write "newbalance = newbalance+$row->coff;" Does this make sense? Link to comment https://forums.phpfreaks.com/topic/237149-php-working-with-js/ Share on other sites More sharing options...
liamloveslearning Posted May 22, 2011 Author Share Posted May 22, 2011 could i do something like this with my JS var credit = "<?php $row->coff ?>" newbalance = newbalance+credit; Link to comment https://forums.phpfreaks.com/topic/237149-php-working-with-js/#findComment-1218827 Share on other sites More sharing options...
liamloveslearning Posted May 22, 2011 Author Share Posted May 22, 2011 I've gotten it working using a numerical value as opposed to a php value so I think its something to do with my php variable? var credit = 2000; newbalance = newbalance+credit; Link to comment https://forums.phpfreaks.com/topic/237149-php-working-with-js/#findComment-1218835 Share on other sites More sharing options...
jcbones Posted May 23, 2011 Share Posted May 23, 2011 Did you try to remove the double quotes: var credit = <?php $row->coff ?>; Javascript doesn't add strings the same as it adds integers. Link to comment https://forums.phpfreaks.com/topic/237149-php-working-with-js/#findComment-1218885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.