Jump to content

fxr

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Everything posted by fxr

  1. condition 1 looks at an int value on the record, if there is a sequence of those higher (or lower) than a certain number e.g 4 records in a row higher than 10 then its set to true. all of them parameters (higher, 4, 10) are dependent on what the user is asking for. condition 2 looks at a different int value on the record. if that value is found or exceeded in the next record, condition 2 is true, if not we look at the next record, and so on.. for output purposes , i must know how many records there is between where condition 1 and condition 2 are found.
  2. OK i will try again.. // pseudocode //user inputted vars $OpenTarget; $userDiff; $target; $targetTime; //other vars $OpenCount=0; $toTargetCount=0; read record to $sql with while loop if ($opentargetreached=true) //check for condition 2 if ($toTargetCount =< $targetTime) // condition has to be met withing certain amount of records. if ($target >= $sql['target']) // success // do success stuff // unset variables set $opentargetreached= false and read a new record and check for condition 1 again endif else // failed to find target within defined amount of records // fail // do fail stuff // unset variables set $opentargetreached= false and read a new record and check for condition 1 again // search for condition 1 if ($userDiff >= $sql['diff']) $OpenCount ++; else $OpenCount = 0; if ($OpenTarget == $OpenCount) $opentargetreached=true; // sets condition 1 = true. clearly, picking up records from the table searching for condition 2 after finding a sequence of records that satisfy condition 1, means i have 'skipped' some records that id rather include in the condition 1 search. i need to work out a way to get back to where i was in the table after a search for condition 2 has completed. hope i am making a little more sense now thanks for any help offered.
  3. OK. i realise i am finding it very hard to explain my issue properly. I will try again.. i have a table of nearly 100,000 records, i am using a while loop to fill an array $sql with the contents of a record. I check for a condition in this record, based on parameters passed by a user, if the condition isnt met , i go back to the start of the loop and get another record. The condition is checked for again, (this condition requires knowledge of the previous record(s)) , if the condition is still not met, we go back to the start of the loop and another record is read.. If eventually the condition is met, a flag is set ($useropentargetreached) and we go back to the start of the loop and grab another record, then another condition from that record is checked for, if its not found then we repeat the loop and get another record, again knowledge of teh previous records is required. I need to keep a count of the number of records between when the 1st condition is met and when the 2nd is found. When that 2nd condition is either found, or not found within x amount of records, the flag ($useropentargetreached) is unset and we go back to teh start of the loop and get a record and start looking for condition 1 again, and so on. The data in the records is essentially just.. of datetime, int, int, int, int, int, int. i dont see the point in muddying the water further posting sample data. (The logic i mentioned in post one stands.) My problem, is trying to build in some kind of 'memory' of where in the table, I was when condition 1 was found , so i can get back there after the search through proceeding records looking for condition 2. Its really not that complicated, i am just struggling to explain it right and my lack of skill with both php and mysql patently aint helping. Just hoping someone can nudge me in the right direction, without finding some offence in my posts
  4. Both conditions depend on comparisons over a sequence of records. I dont think building it into the SQL query will work (tho i am not 100% sure of that) , i need to know the contents of proceeding records to know if either condition has been met. I am struggling to explain my problem well.. and i am sorry for that. this table contains 100,000 records. i will post a section my inadequate tho working code, i imagine only the most persistent of potential helpers will help me work through this issue. $sql = mysql_query("SELECT * FROM $table ORDER BY time ASC") or die(mysql_error()); while($db = mysql_fetch_assoc($sql)) { if ($db['bid_diff'] < 0 ) { $dbnegdiff = $db['bid_diff'] * -1; } else { $dbnegdiff = $db['bid_diff'];} if ($opentargetreached == true) { $timeframe++; if ($timeframe <= $usertimeframetarget) { if ($userhigherlower == 'higher') //short { if ($db['ask_high'] > $maxDD) {$maxDD=$db['ask_high']; } if (rdecimal($db['ask_low']) <= $target) { //$askhigh = rdecimal($maxDD); $maxtp = ($target + $usertp ) - rdecimal($db['ask_low']); $maxDD = rdecimal($maxDD) - ($target + $usertp ); $success++; $hour = get_hour($dbfirsttime); $successarray[$success] = array ( 'hour' => $hour, 'begintime' => $dbfirsttime, 'diff' => $diffstring, 'maxDD' => $maxDD, 'timeframes' => $timeframe, 'maxtp' => $maxtp); //undec vars $opentargetreached=false; $diffstring=''; $timeframe=0; unset($dbfirsttime); unset($dbnegdiff); unset($target); unset($maxtp); unset($hour); $yescount=0; $maxDD=0; } } else // long { if ($db['bid_low'] < $maxDD) {$maxDDL=$db['bid_low']; } if (rdecimal($db['bid_high']) >= $target) { $bidlow = rdecimal($maxDDL); $maxtp = rdecimal($db['bid_high']) - ($target - $usertp ) ; $maxDDL = rdecimal($maxDDL) - ($target - $usertp); $success++; $hour = get_hour($dbfirsttime); $successarray[$success] = array ( 'hour' => $hour, 'begintime' => $dbfirsttime, 'diff' => $diffstring, 'maxDD' => $maxDDL, 'timeframes' => $timeframe, 'maxtp' => $maxtp); //undec vars $opentargetreached=false; $diffstring=''; $timeframe=0; unset($dbfirsttime); unset($dbnegdiff); unset($target); unset($maxtp); unset($hour); //unset($bidlow); $yescount=0; $maxDDL=9999; } } } else //fail in usertimeframe { $fail++; $hour = get_hour($dbfirsttime); //undec vars $failarray[$fail] = array ( 'hour' => $hour, 'begintime' => $dbfirsttime, 'diff' => $diffstring, 'timeframes' => $timeframe); $opentargetreached=false; $diffstring=''; $timeframe=0; unset($dbfirsttime); unset($dbnegdiff); unset($target); unset($open); unset($hour); $yescount=0; $maxDD=0; $maxDDL=0; next; } } else { $diffstring.=', '.$db['bid_diff']; if($userhigherlower=='higher' && $dbnegdiff >= $userdiff && $db['gap'] !=1 && $db['bid_diff'] > 0 && ($prev_hilo !='lower' || prev_hilo !='flat' )) { // good higher open $yescount++; $prev_hilo = 'higher'; if ($yescount==1) {$dbfirsttime =$db['time'];} } elseif($userhigherlower=='lower' && $dbnegdiff >= $userdiff && $db['gap'] !=1 && $db['bid_diff'] < 0 && ($prev_hilo !='higher' || prev_hilo !='flat')) { // good lower open $yescount++; $prev_hilo='lower'; if ($yescount==1) {$dbfirsttime =$db['time'];} } elseif($usernoise >= $dbnegdiff && $db['gap'] !=1 && $allowNoise == true ) { // noise $prev_hilo ='noise'; } else //no good reset vars { $yescount=0; unset($dbfirsttime); unset($dbnegdiff); $prev_hilo = 'flat'; $diffstring=''; } if ($useropentarget==$yescount) { $opentargetreached=true; if ($userhigherlower == 'higher') { //$open = rdecimal($db['bid_open']); $target = rdecimal($db['bid_open']) - $usertp; $maxDD = $db['ask_high']; } if ($userhigherlower == 'lower') { $target = rdecimal($db['ask_open']) + $usertp; $maxDDL = $db['ask_high']; } $prev_hilo = 'flat'; } } }//while
  5. I have a database read it for use in php with : $sql = mysql_query("SELECT * FROM $table ORDER BY time ASC") or die(mysql_error()); while($db = mysql_fetch_assoc($sql)) i loop through this table until i find a valid condition, when its found, i set a flag and return to the start of the loop, where a different condition is looked for in the proceeding records. how would i return to the place in the loop(table) at the next record following where the orignal first condition was found after that 2nd search has completed? basic logic is this: while (record) if (1st condition = true) if (2nd condition) // do stuff set 1st condition = false // NEED to find a way to return to the next record after first conditon is found here. if (1st condition) 1st condition = true. next record.
  6. ok i decided to inspect the http response headers of my test.txt.. meaning i dont need no cookies or server side scripts.. surely the most efficient way of checking for that state change. ll include the code. var LastMod; function checkChanged() { new Ajax.Request("http://XXX.com/check/test2.txt", { onSuccess: function(transport){ var header = transport.getResponseHeader('Last-Modified'); if (LastMod != header && LastMod !=null) {LastMod = header;swfobject.getObjectById("siren").Play();} else LastMod = header; }});} very happy with my solution
  7. I am not sure where to put this question, hopefully here is ok. I have a web app that needs its clients to poll a server every few seconds to check if a specific file has changed. If the file has changed it sends an alert to the client [a swf gets played] . My scripts work fine the majority of time and for the majority of users but my method seems to be issuing a phantom alert to some but not all clients at around the time the server switches over to a new day(midnight). It uses a cookie, which is created on page load to store the last modification date of a file on the server. That cookie value is then later compared with the files' modification date that is returned by a php script called via an ajax request [which is issued every few seconds]. What the file contains is irrelevant as i dont want to bog the server down by opening and reading files every few seconds by maybe 200 clients. i will include relevant code snippets , [it uses the prototypejs library for issuing ajax requests] // on page creation // get file mod time and set cookie lastChange <?php session_start(); $value = filemtime('../check/test.txt'); setcookie("lastChange", $value); ?> function checkChanged() { new Ajax.Request("check_changed.php", { method: 'get', onSuccess: function(transport){ var x = get_cookie ( "lastChange" ); var response = transport.responseText; if (x != response && response != 0) // cookie != last file modification time or invalid response. {swfobject.getObjectById("siren").Play(); set_cookie ( "lastChange", response );}}});} //checkchanged.php <?php if($timeS = filemtime('../check/test.txt')) { echo $timeS;} else echo 0; ?> Now i believe my issue may be caused by this: http://uk.php.net/clearstatcache is anyone able to confirm that this is indeed my issue? and if it is what sort of performance hit would i suffer if i put clearstatcache(); at the beginning of my checkchanged.php script? i would also like to know if there is any other solutions i could use.. and whether or not the way i have decided to approach this problem is entirely foolhardy? I welcome any comments at all, as this issue has bugged me persistently since i have embarked on this project and its pretty much critical to its success. thanks.
  8. yep.. that seems to have done it . thanks! just it should be SELECT * FROM table WHERE column1 > SUBDATE(NOW(), INTERVAL 8 DAY) AND DAYOFWEEK(column1) >= 1;
  9. is anyone capable of writing me a mysql select statement to select all records since 'last sunday' i.e this week, if my records have a field $datetime as type DATETIME? is mysql even capable of doing this, i had a look at INTERVAL and CURTIME and stuff like that, but its just not going in. can anyone bail me out please?
  10. yeah its prototype.. i have worked on this overnight and worked out that using innerHTML was my avenue to success. ll post my code for anyone who may stumble on this or be interested. Relevant snippets of code. <script type="text/javascript"> function DLChange(newHTML){ document.getElementById('tradeID').innerHTML = newHTML; } function sendRequestClose() { new Ajax.Request("sendmailclose.php", { method: 'post', postBody: "tradeID="+$F("tradeID")+"&closeprice="+$F("closeprice"), onLoading: showLoading, //have to add alert onSuccess: function(transport){ var response = transport.responseText || "no response text"; var responder=response.split("<!-- DL -->"); alert("Success! \n\n" + responder[0]); DLChange(responder[1]); }, onFailure: function(){ alert('NO EMAILS SENT - NO RESPONSE FROM SERVER') }, onComplete: hideLoading } ); } </script> .... CLOSE TRADE : <select name="tradeID" id="tradeID"> <!-- PHP --> <?php include 'opentrades.php'; ?> opentrades.php looks like this and is included at the bottom of my sendmailclose.php script. <?php // Make a MySQL Connection mysql_connect("localhost", "ssss", "sssss")or die(mysql_error()); mysql_select_db("db")or die(mysql_error()); $result = @mysql_query("SELECT ID,opentime,pair,openprice,LS FROM logopen"); print "<!-- DL -->"; while ($row = mysql_fetch_assoc($result)) { $tradeID = $row['ID']; $opentime = $row['open_time']; $pair = $row['pair']; $price = $row['open_price'];} $LS = $row['LS']; print "<option value=$tradeID id=$tradeID>$tradeID $LS $pair $price $opentime";} print "</select>"; ?>
  11. ok i have some php code embedded in my html that populates a dropdown list with entries from a mysql. now i need to think how i am going to repopulate that list [i.e pretty much rerun that segment of php code to update the dropdown list] when an ajax enabled action occurs. i have the ajax sorted for other types of updates, but i cant think through the logic for how i am going to update that list after these other events happen. [the dropdown list options need to change after these updates occur] i am using the prototypejs library i will post relevant sections of code.. <script type="text/javascript"> function sendRequestClose() { new Ajax.Request("sendmailclose.php", { method: 'post', postBody: "tradeID="+$F("tradeID")+"&closeprice="+$F("closeprice"), onLoading: showLoading, //have to add alert onSuccess: function(transport){ var response = transport.responseText || "no response text"; alert("Success! \n\n" + response); }, onFailure: function(){ alert('NO EMAILS SENT - NO RESPONSE FROM SERVER') }, onComplete: hideLoading } ); } </script> .... <p> CLOSE TRADE : <!-- PHP --> <?php // Make a MySQL Connection mysql_connect("localhost", "ssss", "sssss")or die(mysql_error()); mysql_select_db("db")or die(mysql_error()); $result = @mysql_query("SELECT ID,open_time,pair,open_price,LS FROM log_open"); print "<select name=\"tradeID\" id=\"tradeID\">"; while ($row = mysql_fetch_assoc($result)) { $tradeID = $row['ID']; $opentime = $row['open_time']; $pair = $row['pair']; $price = $row['open_price']; if ($pair == "eu") {$price = round($price,4);} else {$price = round($price,2);} $LS = $row['LS']; print "<option value=$tradeID id=$tradeID>$tradeID $LS $pair $price $opentime";} print "</select>"; ?> price <input name="closeprice" id="closeprice" type="text" size ="7"> <input type="submit" value="CLOSE" name="submit" onClick="javascript: sendRequestClose();"> </p> I need that dropdown list generated by the php to be recreated after the sendRequestClose javascript is called. Can anyone point me in the right direction please? i am a relative newbie at this and i am struggling to get a grasp of the logic what i have to do here. Thhnaks.
  12. hullo, I have created an xml file, @ --> http://dailygrain.com/EUR_USD_quotes.xml i am trying to parse the contents of it into an array like data structure like this.. day date --> time --> value ......... --> time --> value ......... --> time --> value ......... --> time --> value ......... --> time --> value ......... --> time --> value day date --> time --> value ......... --> time --> value ......... --> time --> value ......... --> time --> value ......... --> time --> value ......... --> time --> value i have searched the internet for tutorials and inspirtaion on how i am going to create this data structure, but i am hitting a creative brick wall. I have read the manual but its going completely over my head. Can anyone offer any suggestions as to how i could proceed? should i consider reformatting my xml file? please help if you can , i have been stuck on this problem for the past week and any code i have created based on examples in the manual and other tutorials , i cant get to work for my xml file as i am struggling to understand how they work. Thanks.
  13. no good fella, ll add a link to the entire code for completeness, i didnt add it as m still at the early stages of bug checking and m a little shy off exposing my noobishness ;p as you can probs see from the code, m not completely sure about when to close db connections.. do i need to open the database for each query, or insert/update? entire code here --> http://rafb.net/p/E3rfGu52.html Now... just pasting it means I HAVE FOUND MY ISSUE . i had an errant quote a few lines above, sorry to waste everyones time ;s its been a long morning ;p so i can mark THIS ISSUE AS RESOLVED. unless someone cares to point out the myriad of other issues probably in there ;p ll get back to my bug checking anyway.. thanks MadTechie.. i couldve been looking for answer in the wrong place for a lot longer, if it hadnt been for your kind intervention.
  14. sorry fella, i meant the INSERT statement *editted now* thanks for lookin tho.. think i just need a little break from it.. hopefully a lightbulb ll go off when i come back to it.
  15. hi can anyone help with this i have fiddled with it for hours , its the INSERT statement its having issues with, i believe, i have tried a variety of quotes around my variables but to no avail; i have tried google, but i cant seem to grasp a general feeling of what the error msg is trying to tell me, so its no help.. mysql> describe calcs; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | week | smallint(6) | YES | | NULL | | | day | tinyint(2) | YES | | NULL | | | low | datetime | YES | | NULL | | | high | datetime | YES | | NULL | | | diff | smallint(3) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ // this is a summarised segment of my code in which i believe the error is contained.. list($time,$quote,$week,$day) = split(",",$_REQUEST["n"]); # n=2008-03-17%2005:30:00,15000,1,1 ; $con = mysql_connect("localhost","fxr",""); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("pam_test", $con); $sql="INSERT INTO calcs (week, day, low, high, diff) VALUES('$week', '$day', '$time', '$time', '0') "; if (!mysql_query($sql,$con)){ die("Error: " . mysql_error()); } // error --> PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /var/www/htdocs/pam/savequote2.php on line ### [which is the select statement] can anyone bail a noob out please?
  16. hi i am working on a web application and i am stuck.. i have a table that looks like this: ....time.........................quote....dif | 2008-03-17 00:00:00 | 15000 | | | 2008-03-17 00:30:00 | 15002 | | | 2008-03-17 01:00:00 | 15004 | | | 2008-03-17 01:30:00 | 15006 | | | 2008-03-17 02:00:00 | 15008 | | | 2008-03-17 02:30:00 | 15010 | | | 2008-03-17 03:00:00 | 15008 | | | 2008-03-17 03:30:00 | 15006 | | | 2008-03-17 04:00:00 | 15004 | | | 2008-03-17 04:30:00 | 15002 | | | 2008-03-17 05:00:00 | 15000 | | | 2008-03-17 05:30:00 | 15002 | | | 2008-03-17 06:00:00 | 15004 | | | 2008-03-17 06:30:00 | 15006 | | | 2008-03-17 07:00:00 | 15008 | | ..etc etc i wanna work out the difference in the quote from the previous 30 minutes and store it in the diff field e.g | 2008-03-17 00:00:00 | 15000 | null/0 | | 2008-03-17 00:30:00 | 15002 | 2 | | 2008-03-17 01:00:00 | 15004 | 2 | ..etc.etc can i do this with a stored procedure or something? or should i use a script..? i just need a nudge in the right direction.. thanks.
×
×
  • 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.