Jump to content

Quostin

Members
  • Posts

    13
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Quostin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the help. I'm going to have to look at an alternate way to send chat right now. Psycho example is cleaner and easier to read, but the page loading went from 1600 B/s to 4.6 KB/s. Thanks for your suggestions!
  2. Okay. I limit it to only 20 messages per load and removed the delete part and it is reading 1,631 b/s every 10 seconds. When looking at chats bigger than mine, it seems to only do like 230 B/s every 5 seconds, but have like 40-50 posts in the chat. I'm curious if it keeping the latest posts, and simply adding one line instead of refreshing the whole chat.
  3. I'm going to remove delete and limit it to 20 or so and see how it goes.
  4. I been working on a chat for a website got most of it done and happy with it, until I monitored it on chrome through the network in task manager and saw that the more text is shown, the of a load it takes. Here is what I have. submitchat.php <? print "<BODY SCROLL='NO' bgcolor='#404040' text='black'>"; print "<body style='overflow: hidden'>"; print "<form action='chatbox.php' method='post' id='banana'>"; print " <input type='text' name='message' id='message' size='100'></textarea>"; print "<input type='submit' name='submit' value='Send'></form>"; ?> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#banana").validate({ debug: false, submitHandler: function(form) { // do other stuff for a valid form $.post('chatcode.php', $("#banana").serialize(), function(data) { $('#log').load('chatlog.php'); $('#message').val(''); }); } }); }); </script> chatlog.php <? include ("connect.php"); ?> <head> <body bgcolor="black"> </head> <? $delete = "DELETE FROM `messages` WHERE `timestamp` < (NOW() - INTERVAL 2 HOUR)"; $deletenow = $db->exec($delete); $getmsg = "SELECT * from messages ORDER BY TIMESTAMP DESC"; $getmsg2 = $db->query($getmsg); while ($getmsg3 = $getmsg2->fetch(PDO::FETCH_ASSOC)) { { $find = "/me"; if ($getmsg3['function'] == $find) { $string1 = "<font color='tan'><i><b>$getmsg3[user] </b><font color='tan'>$getmsg3[message]</font></i>"; } else { $string1 = "<font color='$getmsg3[chatcolor]'><b>$getmsg3[user]: </b></font><font color='white'>$getmsg3[message]</font>"; } echo "$string1<br>"; } } ?> main.php <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <head> <div id="main"> </head> <script type="text/javascript"> var auto_refresh; function start() { auto_refresh = setInterval(fresh, 10000); } function end() { auto_refresh = clearInterval(auto_refresh); } function fresh() { $('#log').load('chatlog.php'); } </script> <script type="text/javascript"> idleTimer = null; idleState = true; idleWait = 1200000; (function ($) { $(document).ready(function () { $('*').bind('mousemove keydown scroll', function () { clearTimeout(idleTimer); if (idleState == true) { $("#log").load('chatlog.php'); start(); } idleState = false; idleTimer = setTimeout(function () { // Idle Event $("#log").load('chatstop.php'); end(); idleState = true; }, idleWait); }); $("body").trigger("mousemove"); }); }) (jQuery) </script> <style> #topframe { width: 100%; position: absolute; left: 50%; top: 0%; ; color: #DDDAD7; height: 60%; overflow:auto; } #bottomframe { width: 100%; position: absolute; left: 50%; top: 60%; ; color: #DDDAD7; height: 40%; overflow:auto; } iframe {width: 100%; border: none; overflow-y: auto; overflow-x: hidden;} </style> <div id="topframe"> <iframe id="top" name="top" src="/home.php" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe> </div> <div id="bottomframe"> <style> body { background-color: #404040; background-image:url('rockblack.jpg'); } #log { color: white; position: absolute; width: 95%; height: 80%; left: 50%; ; top: 15%; padding:5px 5px; background: black; border-radius: 20px; overflow:auto; -moz-border-radius: 20px; /* Firefox 3.6 and earlier */ } </style> <? print "<body text='white' scrolling='1'>"; ?> <div id="chatbox"> <? include ("submitchat.php"); ?> </div> <div id="log"> <? include ("chatlog.php"); ?> </div> </div> </div> Basically, main has submitchat.php and chatlog.php and refreshes #log div with chatlog.php every 10 seconds. Works as it is shown. As I said, as the messages in the database get bigger, so does the chatlog.php file. Is there a way to lessen that load without having to do the whole chat in a different approach?
  5. Oh dang, should have proofread it all... change the $string to $WholeSchool. if 1_contacts.p1contact_no is the whole row name then just do $WholeSchool = "$WholeSchool$WholeSchool2[1_contacts.p1contact_no] , ";
  6. Not sure if this is exactly what you want... if ($destno == "WholeSchool") { $WholeSchool1 = mysql_query("Select * FROM 1_contacts"); while ($WholeSchool2 = mysql_fetch_assoc($WholeSchool1)) { $WholeSchool = "$WholeSchool$WholeSchool2[1_contacts]: $WholeSchool2[p1contact_no] , "; } $WholeSchool = substr($string, 0, -2); mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$WholeSchool', '$message', '$student_id')"); } else { mysql_query("INSERT INTO ".$school_id."_outbox (senderno, destno, message, student_id) VALUES ('$senderno', '$destno', '$message', '$student_id')"); } It is kind of corny, but should work. It will separate each data with a comma and at the end of it all, it deletes the last space and comma to keep it clean. I didn't try inserting it into a database, but echo $WholeSchool gives me the right results.
  7. Okay. I think I understand. I thought he may have been misunderstanding me based on My example. I felt your answer was much more clear, maybe it was explained better. Thank you.
  8. I brought this up yesterday in the mysql forums, but felt that it should have been put here since it can be both related. I tried using examples on top of my head, but decided to do a much better example now with more coding done. Here is what I have: <?php include ("connect.php"); //Has database connection $username = $_SESSION['name']; $sql = "SELECT * FROM players where name= '$username'"; $users1 = $db->query($sql); $users = $users1->fetch(PDO::FETCH_ASSOC); $selmonster = "SELECT * FROM pet where id='$users[pet]'"; $selmonster2 = $db->query($selmonster); $monster = $selmonster2->fetch(PDO::FETCH_ASSOC); $res1 = "select * from spelllevel1 where monstername='$monster[monstername]'"; $res2 = $db->query($res1); $res = $res2->fetch(PDO::FETCH_ASSOC); if ($res[$levelmonster] == "") { print "No spell learned!"; } else { print "Learned $res[$levelmonster]"; } ?> This works great, and does exactly what it supposed to do. It grabs the data from the players data and insert the number from $users[pet] into $monster. Then it uses that $monster to grab the monster name in the spell list. Here is how the spelllevel1 table is set up: monstername | 2 | 3 | 4 | 5 |... Small Purple Slime | Rock Throw | Ground Collapse | Earth Prison | Terras End | ... Now, it uses the $monster[level] to grab the column name and then the data in the column and learns the spell, unless it is blank. It works greats and exactly like I need. The problem is... I'm going to be needing more rows for levels, even more than 100 if I wanted, which can make a lot of columns that may not be needed and needed to expand if I want the monster to get to a higher level. Here is another way I had before I changed it to the one above. monstername | Rock Throw | Ground Collapse | Earth Prison | Terras End | Fireball | .... Small Purple Slime | 2 | 3 | 4 | 5 | 0 | .... The one that I have above is what I want to do it as. The problem is that I don't know how to grab the main column name. I want to run $monster[level] to scan through Small Purple Slime until it finds the exact number from its level, then look at the main column, grab it, and make it learn that. For example: Monster level is 5, it goes through Small Purple Slime and sees 5, then looks at the main column and say "Hey, Column name is Terras End, lets $spelllearn = 'Terras End' and exit and continue with the rest of the code. Is this even possible? Or should I stick with what I have now?
  9. I thought of that too, but not really want I want. I'll try again. There are going to be several columns and several rows alone, and can't have the name being posted so many times. I just want to grab the column name of the value it finds, and then save that column name as a variable. I'm not even sure if it is possible. Each time I had a new column, I would have to add one more row for each time in the database and that seems like it would be a lot more work. This may be better in the php area. You can close this and I'll post there with a better example and more coding. Thank you or the reply.
  10. I been stuck on this for a while, itching my head as I try to think about it. I know columns can print the value in the row under it, but I want to scan the whole row of a name, then look at the column and print the name. For example Name | Apple | Banana | Grape | Orange Eric 1 2 3 4 Bob 2 3 4 1 George 3 4 1 2 I got $res = "select * from fruit where name='Eric'"; $res = $db->query($res); $res = $res->fetch(PDO::FETCH_ASSOC); I want it to look at everything in row where Eric is the name. Then I want to input 2 as a variable and scan through the whole row to match 2 and then display Banana. I know I can do $res[banana] to grab the 2, but I want to do the opposite of that. I wish I could explain it better. I also know that you can do: if ($res[banana] == 2) { Code here } else { More code here } The problem with that is I will be having several columns and will take a long time to check every column
  11. You can close this. I feel a little stupid now. I simply included $sql = mysql_query ("SELECT * FROM players where name='$username'"); $users = mysql_fetch_array($sql); right before the script to refresh the <div>... By reselecting the database, it grabs the newest data from the database... Again, I feel so stupid again.
  12. I'll try to be more clear. http://quostin.x10.mx/clone/ is my test. You would need to login to try it. test for username and testing for password. When you click North, you can see that the left side with location, description and picture will refresh, but the location is still the same. If you click north again, it will show a new location, but it would still be wrong by 1. the description div and npc div needs an exact location from the database to show the right thing to be display. I'm trying to have the data updated when it refreshes the div. I'm assuming that npc and description pages refreshes before the database is updated, even though the update piece of code is before the refresh on npc and description.
  13. I'm trying to show the same data, but updated right away. For example. I want to update my coords on a map and refresh a div to show the new data, but as the code now, it keeps the same data until I reload the page. Here is the code I have now. if ($north) { $ylocation = $users['y'] + 1; if ($ylocation > 5) { $ylocation = 0; } $locationyupdate = ("UPDATE players SET y = '$ylocation' WHERE name='$users[name]'"); mysql_query($locationyupdate) or die("could not register");?> <script type="text/javascript"> $('#npc').load('npc.php'); $('#description').load('description.php'); </script><?} The update code is before the reload script for the two div's. The data DOES change in the database, but the two div's won't display the new data until it is refreshed again. Do I need to reactivate fetch to get the new data?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.