Andy-H Posted July 29, 2008 Share Posted July 29, 2008 I am trying to make a "who's viewing topic" feature for a forum using this code: <script type="text/javascript"> <!-- function loadingUp() { <?php mysql_query("UPDATE `players` SET `pageat` = '$topicid' WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); ?> } function loadingDown() { <?php mysql_query("UPDATE `players` SET `pageat` = '' WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); ?> } //--> </script> <body onLoad="loadingUp();" onUnLoad="loadingDown();"> However instead of processing the PHP on the page load/unload it just reads through it and updates the field to the topic id, then updates it back to blank as the script loads, is there a way I can do this? Link to comment https://forums.phpfreaks.com/topic/117214-solved-calling-php-mysql-inside-a-javascript-function/ Share on other sites More sharing options...
adam84 Posted July 29, 2008 Share Posted July 29, 2008 I dont think you can do it that way. You probably need to use ajax Link to comment https://forums.phpfreaks.com/topic/117214-solved-calling-php-mysql-inside-a-javascript-function/#findComment-602945 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2008 Share Posted July 29, 2008 http://www.phpfreaks.com/forums/index.php/topic,209243.msg951301.html#msg951301 Link to comment https://forums.phpfreaks.com/topic/117214-solved-calling-php-mysql-inside-a-javascript-function/#findComment-602952 Share on other sites More sharing options...
Andy-H Posted July 29, 2008 Author Share Posted July 29, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/117214-solved-calling-php-mysql-inside-a-javascript-function/#findComment-602953 Share on other sites More sharing options...
Andy-H Posted July 29, 2008 Author Share Posted July 29, 2008 I fixed it without AJAX as I cant see the point in learning it just for this. I figured since I have two files that are required in every single file at the top I just added: mysql_query("UPDATE `players` SET `pageat` = '' WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); In my require files and added: mysql_query("UPDATE `players` SET `pageat` = '$topicid' WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); After the file require in my viewtopic.php and: <tr> <td colspan=2><div align="center">Users Viewing This Topic:<br> <br> <?php $lol = mysql_query("SELECT * FROM `players` WHERE `pageat` = '$topicid' ORDER BY `rank` DESC")or die(mysql_error()); while($ass = mysql_fetch_assoc($lol)){ $viewer = $ass['playername']; echo "<a href=\"profile.php?viewuser=".$viewer."\">".$viewer."</a> , "; } ?> </div></td> </tr> To show whose viewing the topic. Thanks for the help guys. Link to comment https://forums.phpfreaks.com/topic/117214-solved-calling-php-mysql-inside-a-javascript-function/#findComment-602963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.