Jump to content

opalelement

Members
  • Posts

    58
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

opalelement's Achievements

Member

Member (2/5)

0

Reputation

  1. I will start off by saying that this is going to be very confusing as I don't find myself a good explainer... Try to bear with me though. I am creating a PHP application that will find the connection between two items on our system. The DB tables are like this: TABLE connections_enabled COL item_id BIGINT(20) TABLE connections COL item_id BIGINT(20) COL connected_to_id BIGINT(20) So then I end up with values like the following: connections_enabled 0001 0002 0003 0004 0005 connections 0001, 0008 0001, 0010 0002, 0004 0002, 0007 0005, 0007 0005, 0008 Then lets say I want to find out how 0001 and 0002 are connected... In my script I will apply the following logic: 1. Get connections of 0001 (returns 0008, 0010) 2. Get connections of each of the returned (0008 => 0001, 0005) (0010 => 0001) so now the 0010 path ends 3. Since 0008 still has 0005 unchecked, we get what 0005 is connected to (returns 0007 and 0008, but 0008 is already used and is therefore dropped) 4. We check what 0007 matches, and sure enough it is connected to 0002. Final result: 0001 => 0008 => 0005 => 0007 => 0002 However, this will be on a much larger scale... each `connections`.`item_id` above only has 2 matches. In reality each one will have between 1 and 500 matches, 300,000 items with connections enabled, and they can go through up to 15 matches (compared to the 5 in the result above). Calling a mysql_query each time will take way too long. My idea is that I have another script that runs every few hours to export all data to a cache folder as arrays in individual files. So the above `connections` table would be like this (not exactly, but similarly so): main.php $connarr = new Array(); require("$idNum.php"); 0001.php $connarr['0001'] = new Array(0008, 0010); 0002.php $connarr['0002'] = new Array(0004, 0007); 0005.php $connarr['0005'] = new Array(0007, 0008); Then I can get the connected items by looping through $connarr[$whateverIdINeed]. I have no doubt that this would take quite a bit of fine-tuning. The question boils down to this: Would it be quicker/more efficient to compare array items require()d from separate files than it would be comparing through the database? If you read all of that, thank you for hanging in there. If you understood it, all opinions would be appreciated. Feel free to ask if you have any questions. Thanks, Opalelement
  2. How can I make my tab (or the window in the task bar) flash using Javascript? I made a PHP/AJAX powered chat program and I want you to be able to see when you have a message. I mean teh flashing from activity, like a regular IM program would do. Thanks, .:Opalelement:.
  3. I am trying to get this chat script to work (from a tutorial here) My current code: <?php if(!isset($_GET['mode'])) { echo <<<REGION <script type="text/javascript"> var sendReq = getXmlHttpRequestObject(); var receiveReq = getXmlHttpRequestObject(); var lastMessage = 0; var mTimer; function getChatText() { if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open("GET", 'chat.php?action=chat&mode=get&last=' + lastMessage, true); receiveReq.onreadystatechange = handleReceiveChat; receiveReq.send(null); } } function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('chat_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.'; } } function handleReceiveChat() { if (receiveReq.readyState == 4) { var chat_div = document.getElementById('div_chat'); var xmldoc = receiveReq.responseXML; var message_nodes = xmldoc.getElementsByTagName("message"); var n_messages = message_nodes.length for (i = 0; i < n_messages; i++) { var user_node = message_nodes[i].getElementsByTagName("user"); var text_node = message_nodes[i].getElementsByTagName("text"); var time_node = message_nodes[i].getElementsByTagName("time"); chat_div.innerHTML += user_node[0].firstChild.nodeValue + ' '; chat_div.innerHTML += '<font class="chat_time">' chat_div.innerHTML += time_node[0].firstChild.nodeValue + '</font><br />'; chat_div.innerHTML += text_node[0].firstChild.nodeValue + '<br />'; lastMessage = (message_nodes[i].getAttribute('id')); } mTimer = setTimeout('getChatText();',2000); } } function sendChatText() { if (sendReq.readyState == 4 || sendReq.readyState == 0) { sendReq.open("POST", 'chat.php?action=chat&mode=send', true); sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); sendReq.onreadystatechange = handleSendChat; var param = 'message=' + document.getElementById('txt_message').value; //param += '&name=Ryan Smith'; //param += '&chat=1'; sendReq.send(param); document.getElementById('txt_message').value = ''; } } function handleSendChat() { //Clear out the existing timer so we don't have //multiple timer instances running. clearInterval(mTimer); getChatText(); } </script> <h2>AJAX Driven Web Chat.</h2> <p id="p_status">Status: Normal</p> Current Chitter-Chatter: <div id="div_chat" class="chat_main" style="border:solid 1px;background-color: #DDCCAA; margin-left: 2px;padding:3px;"> </div> <form id="frmmain" name="frmmain" onsubmit=""> <input type="button" name="btn_get_chat" id="btn_get_chat" value="Refresh Chat" onclick="javascript:getChatText();" /> <input type="button" name="btn_reset_chat" id="btn_reset_chat" value="Reset Chat" onclick="javascript:resetChat();" /><br /> <input type="text" id="txt_message" name="txt_message" style="width: 447px;" /> <input type="button" name="btn_send_chat" id="btn_send_chat" value="Send" onclick="javascript:sendChatText();" /> </form> REGION; } else { if($_GET['mode'] == "get") { $header_auth = true; include("validate.php"); // Validates the login echo <<<REGION <?xml version="1.0" ?><root> <message id="0"> <user>Admin</user> <text>Welcome</text> <time>12:00</time> </message> </root> REGION; } else if($_GET['mode'] == "send") { } } ?> The output of directly accessing the chat.php?action=chat&mode=get&last=0: <root> <message id="0"> <user>Admin</user> <text>Your are not currently in a chat session.</text> <time>7:30</time> </message> </root> I don't understand why it is not returning the chat... Can someone help me?
  4. When using the following in a GD image, it won't parse the letter T in "at", it returns a weird character that is a small N above a small L. I believe it is trying to create a tab character instead of the letter T. How should I get around this? date("d.m \a\t H:i")
  5. I tried is_dir and it returned the . and .., and !is_dir returned the two files, /store/, and /_vti_cnf/ I guess I will just have to do manual checking to make sure it isn't one of those.
  6. For some reason, this script: $maps = array(); echo "1"; if ($handle = opendir('/home2/cisarel/public_html/maps/')) { echo "2"; while (false !== ($file = readdir($handle))) { echo "3"; if (is_file($file) && !in_array($file, array("error_log", "update.php"))) { echo "4"; $maps[] = "$file"; echo "5"; } } closedir($handle); echo "6"; } (ignore teh echos for numbers, those were for seeing where it went) won't catch my php files when run from a cron job, but will catch them when run in a browser. I tried !is_file as a test, and it returned ., .., _vti_cnf, and store (which is a directory) in teh browser, but all of those plus my two php scripts in a cron job. Does is_file not work in a cron job?
  7. Good idea, I forgot that variables can pass through. Thanks:)
  8. I have a GD script that, if $_GET rebuild == true, it will regenerate the image based on database data. If not, it gets a saved image and displays that. All of that works perfectly. The problem I am having is that I want one script that will run all of my rebuilds at once. However, when require()ing or include()ing the scripts that generate the image, it tells me that it cannot find the file. It can find them when I don't have ?rebuild=true, but then it doesn't update them. The code: <?php $maps = array(); if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if (is_file($file) && !in_array($file, array("error_log", "update.php"))) { $maps[] = "$file"; } } closedir($handle); } for($i = 0; $i < count($maps); $i++) { echo "$maps[$i]"; include($maps[$i] . "?rebuild=true"); } ?> Is there any other way to do this? I want it all in one file so I can update all my images with one cron job. This means I can't use <img src="map url"> because the cron job would close it off before the php scripts were done, since the cron-called script is finished.
  9. Lets say I have about 10 scripts, s1.php, s2.php, etc. I want to run all these scripts from scripts.php by using require(), so I only have to run one script in a cron job. Each script takes about a minute to execute. Would I set_time_limit of about 600 at the top of scripts.php, or would I need to set this limit at the top of each s*.php individually for about 60? Thanks, .:Opalelement:.
  10. Look at the GD functions, when uploading just run a few GD functions on the file before saving.
  11. I would SELECT them form the database, set $img1 = $row['fname1'] etc..., and then do an if statement to see if the image url changed... if it did, then set $img1 = $newimg1. then just upload them all with fname1 = $img1, fname2 = $img2, yadda yadda
  12. I belive pagename.php/var would mean that it is in a directory named pagename.php, not an actual file... but that is just a guess, I have never really seen anyone use it the second way.
  13. Where have I gone wrong? Forgive me if I am seeing this incorrectly, but wouldn't that red } mean that $row[] is no longer the mysql result?
×
×
  • 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.