scheda Posted September 28, 2009 Share Posted September 28, 2009 I'm working on a web statistics program and have run into a little snafoo with a function. I think it's just because my brain has stopped working for the day - but if I could get another pair of eyes on it, that'd be great. Here's the function. //get hits per day in a comma seperated list public function get_daily_hits($days) { $daily_hits = array(); $ip = $_SERVER['REMOTE_ADDR']; $time = time(); $num = 0; for($i = $days; $i > 0; $i--) { $days_in_seconds = $i * 86400; $b = $days_in_seconds + 86400; foreach($this -> xml -> hit as $a) { if ($a -> ip != $ip && $a -> time > ($time - $days_in_seconds) && $a -> time < $b) {//FIX THIS LINE! $num++; } } array_push($daily_hits, $num); $num = 0; } $daily_hits = implode(',', $daily_hits); return $daily_hits; } The if statement in the foreach is where I'm having trouble. The function is supposed to create a comma delineated string of how many hits were registered on each day for the number of days entered as an argument. So, as you can see in the if statement, what I'm trying to do is... 1. Weed out the admin's IP 2. Start the search at the end of the day being searched 3. End the search at the beginning of the day. Included below is a sample XML file that I'm trying to pull from. <?xml version="1.0"?> <visits> <hit> <id>0</id> <ip>97.101.183.201</ip> <referrer>http://www.google.com</referrer> <time>1254013189</time> </hit> <hit> <id>1</id> <ip>127.0.0.1</ip> <referrer>http://www.google.com</referrer> <time>1253926689</time> </hit> </visits> It's being read just fine, but the function is just displaying a comma delimited string of 0's - which doesn't match up with the data in the XML file. Thanks in advance for any help you can lend! Quote Link to comment https://forums.phpfreaks.com/topic/175749-need-help-with-simple-function/ Share on other sites More sharing options...
.josh Posted September 28, 2009 Share Posted September 28, 2009 if (($a -> ip != $ip) && ($a -> time > ($time - $days_in_seconds)) && ($a -> time < $b)) {//FIX THIS LINE! Quote Link to comment https://forums.phpfreaks.com/topic/175749-need-help-with-simple-function/#findComment-926165 Share on other sites More sharing options...
oumichaelm Posted September 28, 2009 Share Posted September 28, 2009 It looks like your third line isn't going to be true. $a -> time < $b $b is going to always be much smaller than the current time. do you mean $a -> time < ($time +$b) Quote Link to comment https://forums.phpfreaks.com/topic/175749-need-help-with-simple-function/#findComment-926180 Share on other sites More sharing options...
scheda Posted September 28, 2009 Author Share Posted September 28, 2009 Yeah! That was it. Thanks a ton. I guess this was one of those things where I just need to do the actual math myself and see where that takes me. Thanks again. It looks like your third line isn't going to be true. $a -> time < $b $b is going to always be much smaller than the current time. do you mean $a -> time < ($time +$b) Quote Link to comment https://forums.phpfreaks.com/topic/175749-need-help-with-simple-function/#findComment-926370 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.