eon201 Posted November 16, 2007 Share Posted November 16, 2007 Hey, Im doing a quick sum with unix timestamps within a loop to work out if the array is within my specified time frame, and if y or n then do something else. Here is my code so far... $timenow = time(); while($row = mysql_fetch_array( $result )) { echo "Timenow = $timenow<br/><br/>"; echo $row['ip']. " -- "; echo $row['url']. " -- "; echo $row['date']. " -- "; $ip[] = $row['ip']; $url[] = $row['url']; $date[] = $row['date']; $timediff = $timenow - $date; if ($timediff <='3600'){ echo "This one IS within an hours time difference comparitive to NOW<br/><br/>"; } if ($timediff >'3600'){ echo "This one IS NOT within an hours time difference comparitive to NOW<br/><br/>"; } } For some reson im getting the error... Fatal error: Unsupported operand types for this line "$timediff = $timenow - $date;" ??? Why is this. It looks ok to me. Anyhelp would be appreciatted! Quote Link to comment Share on other sites More sharing options...
nezbo Posted November 16, 2007 Share Posted November 16, 2007 I am prity new to PHP but i will have a go anyway is your $row['date'] in unix time stamp? Neil Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 16, 2007 Author Share Posted November 16, 2007 yep... For instance if i echo $ip $url $date i get xx.xx.xxx.xxx /partners/timesonline/tb-09nov07.php 1194823827 and if I echo $timenow i get 1195206642. I just cant see the problem here. they are both numeric values. Quote Link to comment Share on other sites More sharing options...
nezbo Posted November 16, 2007 Share Posted November 16, 2007 out of interest should $date[] = $row['date']; not be $date = $row['date']; i think i might be the square array brackets. Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 16, 2007 Author Share Posted November 16, 2007 Hey cool. You fixed it thanks!!! But for the future... Whats the deal with the square brackets?? What difference does that make? ??? Thanks Eon201 Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 16, 2007 Share Posted November 16, 2007 Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. like nezbo did $date = $row['date']; Square brackets (from php manual) An opening square bracket introduces a character class, terminated by a closing square bracket. A closing square bracket on its own is not special. If a closing square bracket is required as a member of the class, it should be the first data character in the class (after an initial circumflex, if present) or escaped with a backslash. Quote Link to comment Share on other sites More sharing options...
alecks Posted November 16, 2007 Share Posted November 16, 2007 Hey cool. You fixed it thanks!!! But for the future... Whats the deal with the square brackets?? What difference does that make? ??? Thanks Eon201 adding the [] makes it an array, in which case you cant subtract whole arrays at a time (you'd have to do it one value at a time) or arrays from strings, et cetera. $timediff = $timenow - $date[0]; Probably would have worked as well if you wanted it to be an array Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted November 16, 2007 Share Posted November 16, 2007 Actually $var[] = something will append to an array. The array should exist before doing so or it will result in an E_NOTICE. Quote Link to comment 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.