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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Andy-H Posted July 29, 2008 Author Share Posted July 29, 2008 Thanks Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.