- // K, background story: I installed a chat on my website, it's coded with a mixture of JavaScript, PHP, and MySQL.
- // MySQL tables are ajaxim_blocklists (blocked users), ajaxim_buddylists (this one should be obvious :P), ajaxim_chats (chatrooms), ajaxim_messages
- //(messages sent), and ajaxim_users (once again, obvious).
- //Fields for blocklists: id, user, buddy
- //Fields for buddylists: id, user, buddy, group
- //Fields for chats: room, user, id
- //Fields for messages: recipient, sender, message, type, stamp, id
- //Fields for users: username, password, email, is_online, last_ping, last_ip, banned, admin, buddyicon, profile, id
- //So, I registered a user named "ChatBot", but didn't use the site to log in
- //Instead, I went into PHPMyAdmin, and set is_online to '1' (meaning online)
- //Next, I created a .php file "Bot.php"
- <?php
- require('config.php');
- mysql_connect($sql_host, $sql_user, $sql_pass);
- mysql_select_db($sql_db);
- $res = mysql_query("SELECT message FROM ".SQL_PREFIX."messages WHERE type = 'msg'");
- while($arr = mysql_fetch_row($res)){
- echo $arr[0]."<br />";
- }
- ?>
- //So, that tells it to select the messages.
- //My first problem is that I need it to select more than just the message. I need it to select sender, recipient, and message.
- //Next problem is saving it to text.
- //I asked someone how to use PHP to save something to a .txt file.
- //He gave me this:
- $myFile = "File.txt";
- $fh = fopen($myFile, 'w') or die("can't open file");
- $stringData = "$log\n";
- fwrite($fh, $stringData);
- $stringData = "meow\n";
- fwrite($fh, $stringData);
- fclose($fh);
- //Next step, he said, was to save $res to a string, and write that string to the document, but he signed out before I had time to ask him how
- //to do that.
- //Another thing I want to do, is perhaps instead of .txt, make it .html, so I can format it, if at all possible. I want to have a table, sort of
- //like this:
- __________________________________________________________________
- | Sender | Recipient | Message |
- ------------------------------------------------------------------
- | * | * | * |
- ------------------------------------------------------------------
- //Where * corresponds to the text that goes in that field.
- //Except, hopefully an actual table, instead of just symbols.
- //Then, based off of this, I'll be able to create tables where type = 'event' or type = 'chatmsg'