Jump to content

chaking

Members
  • Posts

    68
  • Joined

  • Last visited

Everything posted by chaking

  1. wow yeah - I should have thought of that too - I'll have to check if that matches up consistently tomorrow. Thanks for the follow up
  2. hmm... good idea, however I don't know if that would work... e.g. take this record: Month: 3 Day: 0 Week: 5 Timezone: Azores Daylight Savings Time I believe this references the last sunday in March... if we were to do (5*7)+0 = 35th day of March?
  3. I'm working on daylight savings time around the world and the database I'm drawing the information from lists the start of daylight savings time with the month, day, week, hour, minute and second it starts. Initially I thought I could throw that information into mktime() and get the timestamp, however once I started doing it I realized the `week` part screws it all up. mktime is setup as mktime (hour, minute, seconds, month, day, year) So you can't add in the week of the month. So if I have the following information, anyone know how I can get a timestamp?: Month: 11 Day: 0 Week: 1 Hour: 2 Minute: 0 Seconds: 0
  4. I'm trying to match a few things here and I'm getting a little confused - any help would be appreciated: $s = "SELECT DISTINCT DEVID, INPUTDEVID, MACHINE FROM EVENTS WHERE (EVENT_TIME_UTC BETWEEN '".$start."' AND '".$end."') AND ((EVENTTYPE = 0 AND EVENTID = 0) OR (EVENTTYPE = 4 AND EVENTID IN (2,8,10,53,413,431))) AND (MACHINE = ".$machine.")"; So I'm trying to find any event that has an eventtype of 0 AND an eventid of 0... OR any eventtype of 4 and eventid in (2,8,10,53,413,431). I do NOT want an eventtype of 4 and an eventid of 0. I'm getting a bit confused on how to convey this in the sql statement. I thought I could separate it with parentheses and that would do the trick, but I'm not so sure Any suggestions?
  5. Thanks! Do you happen to know the process behind those functions? I'd be interested to see how it's actually broken down
  6. Ok, so I know how to convert an IP address into an integer... like so: IP: 10.11.12.13 $a = 10 $b = 11 $c = 12 $d = 13 ($a * 256 to the third) + ($b * 256 squared) + ($c * 256) + ($d) = the integer or ($a * 16777216) + ($b * 65536) + ($c * 256) + ($d) = the integer Now, how do you take the final integer and and convert it back to a regular ip address with decimals and all?
  7. The array is something like: <?php $a = array(1,0,1,0,1,0,0,1,1); ?> Is there a way to evaluate the array to see if 2 1's are consecutive? Or if this is easier to read: <?php $a = array("IN","OUT","IN","OUT","IN","OUT","OUT","IN","IN"); ?> I'm trying to execute code anytime 2 INs are consecutive. This might not be the best way to go about it, but basically I'm trying to determine if something was done before it's other required action has been completed. So I query the dB and select all of its events in order of the time of the event, and then output it into an array so that I can tell if the proper conditions were met. If there were 2 INs before an OUT, then that's a problem and needs to be echoed out...
  8. The answer is in the sql statement... so instead of grabbing the string from the datetime field, it can be converted to unix timestamp before outputting the data as so: SELECT stamp = DATEDIFF(s, '19700101', some_column) FROM EVENTS WHERE some_column > 'xxx' And that solves that - w00t
  9. The answer would be: SELECT stamp = DATEDIFF(s, '19700101', column) FROM EVENTS WHERE column > 'xxx'
  10. Try putting the following at the top: $state_totals = array();
  11. <?php $a = "Hello"; <-mysql result $b= "Hello"; <-string you want to match if ($a == $b){ $a = "<font color = red>".$a."</font>"; } ?> Might not be the prettiest way of doing it, but it works.
  12. are you using the mssql.dll for your connections? There was a bug with select statements that limited return to 256 characters with that .dll - What setup do you have? If windows try using the sqlsrv.dll instead. It's got a different API which is a pain, but it apparently resolves a lot of flaws that the mssql.dll has. http://www.microsoft.com/downloads/details.aspx?FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9&displaylang=en
  13. Is it possible to select a datetime field as a unix timestamp? I was selecting the string and then converting with `strtotime` but that leaves off the seconds, so if there's a built in function that would be great -
  14. That's awesome - thanks. I'm learning slowly...
  15. Ok, so thinking about it I guess I could add +12 to the `i` if the `A=='PM'`, I'm still struggling on how to explode that date into pieces though
  16. So after thinking everything was working perfectly, I just noticed that a script that uses the function `strtotime` to convert a string (m/d/Y g:i:s A) into a unix timestamp doesn't actually return the correct seconds... instead it just leaves it at the closest minute (m/d/Y g:i A). I need a way to grab a date formatted as m/d/Y g:i:s A and convert it to the exact unix timestamp. I believe using mktime could work, however I'm not sure how to break up the date so that I can put each individual piece where it's supposed to go in the mktime function: So based on the format `m/d/Y g:i:s A` it will need to end up as mktime(g, i, s, m, d, Y) It would be great to get some help on how to break up the string to fit it into the mktime, but there's also a pretty big issue and that's the `A` at the end. It's AM or PM, so any ideas on how to convert that correctly would be appreciated too... Thanks
  17. Thanks, I'm pretty sure you're right - My sql statements aren't so great... I think I need a bit of help though - Here's the statements I have to run: <?php $eventids = "EVENTID = 8 OR EVENTID = 10 OR EVENTID = 2 OR EVENTID = 431 OR EVENTID = 18 OR EVENTID = 4 OR EVENTID = 6 OR EVENTID = 20 OR EVENTID = 5 OR EVENTID = 7 OR EVENTID = 76"; $sql1 = "SELECT NAME,PANELID FROM ACCESSPANE WHERE (PANELTYPE = 14 OR PANELTYPE = 19 OR PANELTYPE = 59 OR PANELTYPE = 63 OR PANELTYPE = 10) ORDER BY NAME ASC" $sql2 = "SELECT DISTINCT DEVID FROM EVENTS WHERE (MACHINE = ".**(Panelid from sql1)**." ) AND (".$eventids.") AND (EVENTTYPE = 4) AND (EVENT_TIME_UTC >= '".$yesterday."')"; $sql3 = "SELECT DISTINCT INPUTDEVID, EVENTID FROM EVENTS WHERE (MACHINE = ".**(Panelid from sql1)**." ) AND (DEVID = ".**(devid from sql2)**.") AND (".$eventids.") AND (EVENTTYPE = 4) AND (EVENT_TIME_UTC >= '".$yester."')"; ?> So is it possible to combine all 3 into 1? I imagine so, but I'm having trouble doing it -
  18. Can anyone walk me through dumping some data to a temp file and then using the server to search through it so that I won't have to make so many calls to the db?
  19. My queries are currently taking over 20 minutes to run and I have a feeling I'm probably doing it rather poorly, was hoping someone could suggest an alternative... The jist of the script is to go through the database and find the last time a certain entry was made and then put it into an array for later. It's going through hundreds of thousands of rows and so it's taking entirely too long. After I populate the array, I then get the unique values from it and run another set of queries... to see if the canceled state of what I was originally looking for appears after the time of the active state (the original search and array). So I run a SELECT COUNT(*) as ... WHERE TIME > ORIGINAL_TIME... If it returns 0 I output the result saying the original active state never had a canceled entry. Any optimizations would be hugely appreciated - thanks! <?php- while ($a = mssql_fetch_assoc($sql)){ $b = "SELECT PANELID, DEVICEID, INPUTDEVID FROM EVTALMLINK WHERE ALID= " . $a['ALID'] . ""; $b2 = mssql_query($b, $cxn); while ($c = mssql_fetch_assoc($b2)){ $sql2 = "SELECT MAX(EVENT_TIME_UTC) as TIME FROM EVENTS WHERE (MACHINE = " . $c['PANELID'] . ") AND (EVENTID = " . $xxx . ") AND (EVENTTYPE = 4) AND (INPUTDEVID = " . $c['INPUTDEVID'] . ") AND (DEVID = " . $c['DEVICEID'] . ") AND (EVENT_TIME_UTC >= '" . $yester . "') GROUP BY DEVID, INPUTDEVID"; $query2 = mssql_query($sql2, $cxn); while ($cc = mssql_fetch_assoc($query2)){ $thearray[] = $c['PANELID'] . "|" . $c['DEVICEID'] . "|" . $c['INPUTDEVID'] . "|" . $cc['TIME'] . "|" . $xxx; } } } $thearray = array_unique($thearray); foreach ($thearray as $vv => $ll){ list($panel,$device,$input,$time,$type) = explode("|", $ll); $sql = "SELECT COUNT(*) as MYCOUNT FROM EVENTS WHERE (MACHINE = " . $panel . ") AND (EVENTID = " . $yyy . ") AND (EVENTTYPE = 4) AND (EVENT_TIME_UTC > '" . $time . "') AND (INPUTDEVID = " . $input . ") AND (DEVID = " . $device . ")"; $query = mssql_query($sql, $cxn); $res = mssql_fetch_assoc($query); if ($res['MYCOUNT'] == 0){ echo "......various code....."; } ?>
  20. You're looking for chained selects... something like: http://www.dhtmlgoodies.com/index.html?whichScript=ajax_chained_select
  21. In case anyone is interested, here's how it ended up: <?php while ($row = mssql_fetch_assoc($qq)) { $c[] = $row['MACHINE'] . "-" . $row['DEVID'] . "-" . $row['INPUTDEVID'] . "-" . $row['EVENTTYPE'] . "-" . $row['EVENTID']; } $d = array_count_values($c); $g = array_unique($c); foreach ($g as $e => $f) { $zz["$f"] = $d["$f"]; } arsort($zz); foreach ($zz as $aa => $xx){ list($a1, $a2, $a3, $a4, $a5) = explode("-",$aa); $sql6 = "SELECT READERDESC FROM READER WHERE PANELID = '" . $a1 . "'"; $sql6 .= " AND READERID = '" . $a2 . "'"; $tttt = mssql_query($sql6, $cxn2); $row6 = mssql_fetch_assoc($tttt); $sql7 = "SELECT NAME FROM ALARMINPUT WHERE PANELID = '" . $a1 . "'"; $sql7 .= " AND ALARMPID = '" . $a2 . "' AND INPUTID = '"; $sql7 .= $a3 . "'"; $ttttt = mssql_query($sql7, $cxn2); $row7 = mssql_fetch_assoc($ttttt); echo $xx . " | " . $row6['READERDESC'] . " | " . $row7['NAME'] . " | " . $bb[$a4][$a5] . "<br />"; } ?>
  22. Ahh, I think I'll just use an sql statement to get the count for each of them - Thanks
  23. Actually, that's outputting the number of times that specific machine or devid et al. shows up in the array, but it's the combination that matters... So let's say: Machine = 4 devid = 20 inputdevid = 11 eventtype = 4 eventid = 0 What I need to match is how many times all of those values are matched exactly together. If the eventid changes to 1, that would be a separate match/count. I'm thinking maybe I should just put them all under 1 key with a csv or some delimiter and then just explode in while iterating through a loop and match that way?
  24. fantastic - thanks for the quick response mjdamato
×
×
  • 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.