grant Posted December 23, 2011 Share Posted December 23, 2011 ok as you no grpg has it own time updater for who online and stuff but mite is giving me slow queries witch is slowing my site down lags really bad when there is about 30 - 40 users on at one time # Thu Dec 22 16:02:56 2011 # Query_time: 7.208091 Lock_time: 0.000047 Rows_sent: 0 Rows_examined: 1 use warror_wart; UPDATE `warriorusers` SET `lastactive` = '1324594969' WHERE `id`='733' # Thu Dec 22 16:09:36 2011 # Query_time: 3.630811 Lock_time: 0.000060 Rows_sent: 0 Rows_examined: 1 use warror_wart; UPDATE `warriorusers` SET `lastactive` = '1324595372' WHERE `id`='186' here is the code am using any help would be great thanks i have this in my header usertime($user_class->id, time()); this is in my classes function usertime($user, $time){ $resultaf = mysql_query("SELECT * FROM `warriorusers` WHERE `id`='$user'"); $worked = mysql_fetch_array($resultaf); $itemexist = mysql_num_rows($resultaf); if($itemexist == 0){ } else { $resultbb = mysql_query("UPDATE `warriorusers` SET `lastactive` = '$time' WHERE `id`='$user'"); } } Quote Link to comment Share on other sites More sharing options...
Spudinski Posted December 23, 2011 Share Posted December 23, 2011 Everything looks fine, even though it could have been coded better. How many users do you have at the moment, and how does your "warriorusers" look? (format) Quote Link to comment Share on other sites More sharing options...
grant Posted December 23, 2011 Author Share Posted December 23, 2011 i have 734 user but only lags when there are more than 30 - 40 users online and my warriorusers are ok not sure wot you mean better coded ? Quote Link to comment Share on other sites More sharing options...
Spudinski Posted December 23, 2011 Share Posted December 23, 2011 I mean the table schema. It is possible that the mysql service is having conflict whilst converting data types, but with that amount of users it shouldn't slow down at all. Try passing the timestamp and user id as integers to the database, rather than strings(as they are being sent currently). Quote Link to comment Share on other sites More sharing options...
grant Posted December 23, 2011 Author Share Posted December 23, 2011 i try it but may need to change my game time timestamp to stop it from lagging as its pissing me off i have removed the code to see if it helps and the games not lagging any more so i just going to have to use some other way to get the users to show online and 24 list and i think the code not working to well going in to the db is there any way to make a 2 part table in the db for users to split the users in to 2 tables ? Quote Link to comment Share on other sites More sharing options...
grant Posted December 24, 2011 Author Share Posted December 24, 2011 Firstly, you are creating an array that you don't even know exists, why? Assuming warriorusers only has 1 row per user, you can use something like: function usertime($user, $time) { $resultaf = mysql_query("SELECT `id` FROM `warriorusers` WHERE `id` = '{$user}' LIMIT 1"); if(mysql_num_rows($resultaf)) { mysql_query("UPDATE `warriorusers` SET `lastactive` = '{$time}' WHERE `id` = '{$user}' LIMIT 1"); } } not help wot ever way i put the code try 4 ways not helped one bit is there any other way to to grab the time without useing that $time(); ????? and thanks for the help 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.