rofl90 Posted July 10, 2008 Share Posted July 10, 2008 This function outputs what it shouldn't. It should output That it worked, instead it outputs that it doesn't. Output: 2008-06-07 00:00:00 2008-06-08 00:00:00 Notice: Undefined offset: 3 in /opt/local/share/httpd/charlie/wib_3.3/macdaddy/includes/database_helper.php on line 279 Catchable fatal error: Object of class DatabaseHelper could not be converted to string in /opt/local/share/httpd/charlie/wib_3.3/macdaddy/includes/activity.php on line 297 What's outputting it: <?php error_reporting(E_ALL); define('LOGIN_TYPE', 'PUBLIC'); require "header.php"; if($activity->spikeDay()) { echo "It was matched, in a real situation we'd of emailed etc already!"; } else { echo "Damni, it wasn't sent..and it should of"; } ?> function spikeDay(){ global $dbh; $starttime = $this->getStamp("last_day"); $endtime = $this->getStamp("day"); $starttime = strtotime($starttime); $endtime = strtotime($endtime); $starttime = strtotime("-1 month, -2 days", $starttime); $endtime = strtotime("-1 month, -2 days", $endtime); $starttime = date("Y-m-d H:i:s", $starttime); $endtime = date("Y-m-d H:i:s", $endtime); echo $starttime . "<br />" . $endtime; $testingSQL = $this->dbh->query("SELECT * FROM ".LOGGING_DB.".`spike` WHERE `intervalTime` = 'day'", 'execute', __LINE__, __FILE__); while($spikeDayQL = $this->$dbh->getArray($testingSQL, __LINE__, __FILE__)) { if($spikeDayQL['conditionType'] == "PercentageChange") { $n = array(); for ($i=0; $i<7; $i++) { $new[date('m-d', strtotime("+$i days", $starttime))] = 0; // create empty array for time period } $sqly = "SELECT DATE_FORMAT(stamp, '%m-%d%') , `count` FROM ".LOGGING_DB.".`activityDay` WHERE `line` = '{$spikeDayQL['monitor']}' AND `stamp` BETWEEN '$starttime' AND '$endtime' "; $res = mysql_query($sqly) or die (mysql_error()); while (list($k, $count) = mysql_fetch_row($res)) { $new[$k] += $count; } $theLeast = 99999999999999; $theMost = 0; foreach($new as $newa => $newb) { $theMost = max($newb, $theMost); $theLeast = min($newb, $theLeast); } if($theMost == $theLeast) $changePercentage = 0; //the formula to calculate what the percentage of the extremes are (changes between) $thePercentage = (($theMost - $theLeast) / $theLeast) * 100; ($thePercentage > 0) ? $isPos = true : $isPos = false; return ($isPos) ? (($thePercentage >= $spikeDayQL['changeBy']) ? true : false) : (($thePercentage >= $spikeDayQL['changeBy']) ? false : true); } elseif($spikeDayQL['conditionType'] == "WhenLineReaches") { $sqly = "SELECT * FROM ".LOGGING_DB.".`activityDay` WHERE `line` = '{$spikeDayQL['monitor']}' AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` >= {$spikeDayQL['changeBy']}"; echo $sqly; $countSpikes = mysql_query($sqly); return (mysql_num_rows($countSpikes) >= 1) ? true : false; echo mysql_num_rows($countSpikes); echo "yo!"; } elseif($spikeDayQL['conditionType'] == "WhenLineDropsBelow") { $sqly = "SELECT * FROM ".LOGGING_DB.".`activityDay` WHERE `line` = '{$spikeDayQL['monitor']}' AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` < {$spikeDayQL['changeBy']}"; $countSpikes = mysql_query($sqly); return (mysql_num_rows($countSpikes) >= 1) ? true : false; } } Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/ Share on other sites More sharing options...
rofl90 Posted July 10, 2008 Author Share Posted July 10, 2008 no replies? Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586941 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 We have no idea what that function does and I'm fairly sure that no one wants to search through that huge wall of text to find the problem. How about giving us an idea? Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586946 Share on other sites More sharing options...
cooldude832 Posted July 10, 2008 Share Posted July 10, 2008 You never declared a new object thus saying $activity->function() will produce an error. Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586959 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I think he did it somewhere else. I could be wrong though. Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586961 Share on other sites More sharing options...
rofl90 Posted July 10, 2008 Author Share Posted July 10, 2008 Yes, I did. the function checks for a spike in activity, eg it checks logs for the last 6 days and gets the min and max, calculates the percentage of change then checks if the percentage is big enough to trigger an spike alert. this could also be "drops below" and "reaches" which are self-explanatory. the whole array thing in the percentage part just creates rows with "1" in if they dont exist as 0 is an infinite percentage if it is relative. Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586967 Share on other sites More sharing options...
cooldude832 Posted July 10, 2008 Share Posted July 10, 2008 I don't see it <?php error_reporting(E_ALL); define('LOGIN_TYPE', 'PUBLIC'); require "header.php"; if($activity->spikeDay()) { echo "It was matched, in a real situation we'd of emailed etc already!"; } else { echo "Damni, it wasn't sent..and it should of"; } ?> Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586970 Share on other sites More sharing options...
lvtrii Posted July 10, 2008 Share Posted July 10, 2008 Offset error, database handler... gut instinct is telling me it's this line: while (list($k, $count) = mysql_fetch_row($res)) { $new[$k] += $count;[b] <-- HERE[/b] } Try using: while ($row = mysql_fetch_row($res)) { $new[$row['theDate']] += $row['count']; } And in the SELECT query, change the fields to: DATE_FORMAT(stamp, '%m-%d%') as theDate, `count` Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586976 Share on other sites More sharing options...
rofl90 Posted July 10, 2008 Author Share Posted July 10, 2008 same error. Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-586988 Share on other sites More sharing options...
lvtrii Posted July 10, 2008 Share Posted July 10, 2008 while ($row = mysql_fetch_row($res)) { $new[0] += $row['count']; } Try that.. I'm convinced it's the fact you're trying to use the date field as a key that it doesn't like. Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-587003 Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Can you at least point out line 279? Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-587005 Share on other sites More sharing options...
rofl90 Posted July 10, 2008 Author Share Posted July 10, 2008 public function query($query, $location='') { $query=trim($query); // Grab the first word from a query which is assumed to be the query type (ie select insert delete update etc...) $explosion=explode(' ', strtolower(trim(str_replace('(','',$query)))); $explosion=array_shift($explosion); $query_type = (strtolower($explosion) == 'select') ? 'query':'execute'; $pieces = explode(' ', $location); $this->_query($query, $query_type, $pieces[0], $pieces[3]); {{{{{{MEEEEEEEEEEE}}}}} return true; } If you were referring to the other: function spikeDay(){ global $dbh; $starttime = $this->getStamp("last_day"); $endtime = $this->getStamp("day"); $starttime = strtotime($starttime); $endtime = strtotime($endtime); $starttime = strtotime("-1 month, -2 days", $starttime); $endtime = strtotime("-1 month, -2 days", $endtime); $starttime = date("Y-m-d H:i:s", $starttime); $endtime = date("Y-m-d H:i:s", $endtime); echo $starttime . "<br />" . $endtime; $testingSQL = $this->dbh->query("SELECT * FROM ".LOGGING_DB.".`spike` WHERE `intervalTime` = 'day'", 'execute', __LINE__, __FILE__); while($spikeDayQL = $this->$dbh->getArray($testingSQL, __LINE__, __FILE__)) { {{{MEEE}}} if($spikeDayQL['conditionType'] == "PercentageChange") { $n = array(); for ($i=0; $i<7; $i++) { $new[date('m-d', strtotime("+$i days", $starttime))] = 0; // create empty array for time period } $sqly = "DATE_FORMAT(stamp, '%m-%d%') as theDate, `count` FROM ".LOGGING_DB.".`activityDay` WHERE `line` = '{$spikeDayQL['monitor']}' AND `stamp` BETWEEN '$starttime' AND '$endtime' "; $res = mysql_query($sqly) or die (mysql_error()); while ($row = mysql_fetch_row($res)) { $new[$row['theDate']] += $row['count']; } $theLeast = 99999999999999; $theMost = 0; foreach($new as $newa => $newb) { $theMost = max($newb, $theMost); $theLeast = min($newb, $theLeast); } if($theMost == $theLeast) $changePercentage = 0; //the formula to calculate what the percentage of the extremes are (changes between) $thePercentage = (($theMost - $theLeast) / $theLeast) * 100; ($thePercentage > 0) ? $isPos = true : $isPos = false; return ($isPos) ? (($thePercentage >= $spikeDayQL['changeBy']) ? true : false) : (($thePercentage >= $spikeDayQL['changeBy']) ? false : true); } elseif($spikeDayQL['conditionType'] == "WhenLineReaches") { $sqly = "SELECT * FROM ".LOGGING_DB.".`activityDay` WHERE `line` = '{$spikeDayQL['monitor']}' AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` >= {$spikeDayQL['changeBy']}"; echo $sqly; $countSpikes = mysql_query($sqly); return (mysql_num_rows($countSpikes) >= 1) ? true : false; echo mysql_num_rows($countSpikes); echo "yo!"; } elseif($spikeDayQL['conditionType'] == "WhenLineDropsBelow") { $sqly = "SELECT * FROM ".LOGGING_DB.".`activityDay` WHERE `line` = '{$spikeDayQL['monitor']}' AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` < {$spikeDayQL['changeBy']}"; $countSpikes = mysql_query($sqly); return (mysql_num_rows($countSpikes) >= 1) ? true : false; } } Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-587010 Share on other sites More sharing options...
rofl90 Posted July 10, 2008 Author Share Posted July 10, 2008 Btw the while change didn't work -- same error. Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-587012 Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 After this line.... $pieces = explode(' ', $location); Place this.... print_r($pieces);exit; What does it produce? Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-587015 Share on other sites More sharing options...
rofl90 Posted July 10, 2008 Author Share Posted July 10, 2008 Array ( [0] => execute ) thats a 0 by the way Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-587020 Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Then there is your problem, $pieces[3] does not exist. Link to comment https://forums.phpfreaks.com/topic/114156-this-function-wont-work/#findComment-587041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.