wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 When using that code i get this error:[quote]Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\public_html\RPG\site.php on line 30[/quote]Thanks for all your help pkSMLThanks.Peter.**Edit** line 30 is:[code]if (strtotime("$x['dateadded']") > $sevenDays) {[/code] Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 16, 2006 Share Posted September 16, 2006 What's on line 30 of site.php?BTW, we both moved from nOObie to non-spammers on this forum ;D*EditI see your edited post.Change [code]if (strtotime("$x['dateadded']") > $sevenDays) {[/code] to [code]if (strtotime($x['dateadded']) > $sevenDays) {[/code]Does this change the output? Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 woo, not a noobie any more :PI edited my previous post saying what line 30 was :)Thanks again.Peter. Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 Ah sorry, didn't replace all of the code, thats why i got the error.It doesn't print anything and doesn't display an image. Any ideas?Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 16, 2006 Share Posted September 16, 2006 Try this. I changed some variables around.If it doesn't work, try the diagnostic version (below). Then show me the output of the diagnostic version.[code]<?phpdate_default_timezone_set("US/Eastern");while ($x = mysql_fetch_array($result)) { list($year, $mon, $day) = explode('-', $x['dateadded']); $sevenDays = (7 * 24 * 60 * 60); // 604,800 seconds in 7 days $entryTime = strtotime("$year-$mon-$day") $now = strtotime("now"); if (($now - $entryTime) < $sevenDays) { // show your image here since it's new! echo "<img src='/images/new.gif'>"; }}?>[/code]Diagnostic version:[code]<?phpdate_default_timezone_set("US/Eastern");while ($x = mysql_fetch_array($result)) { list($year, $mon, $day) = explode('-', $x['dateadded']); $sevenDays = (7 * 24 * 60 * 60); // 604,800 seconds in 7 days $entryTime = strtotime("$year-$mon-$day") $now = strtotime("now"); if (($now - $entryTime) < $sevenDays) { // show your image here since it's new! echo "<img src='/images/new.gif'>"; } else { print "<PRE>"; print '$year = '.$year."\n"; print '$mon = '.$mon."\n"; print '$day = '.$day."\n"; print "\$x['dateadded'] = ".$x['dateadded']."\n"; print '$sevenDays = '.$sevenDays."\n"; print 'strtotime("$year-$mon-$day") = '.strtotime("$year-$mon-$day")."\n"; print "</PRE>"; }}?>[/code] Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 16, 2006 Share Posted September 16, 2006 Try my last post first. If problems arise, please provide the URL to the site you're working on. It might give me a little more insight to help you.Also, to make this a lot easier, could you provide FTP access to your site? Then I could see the entire source code and it would be a lot easier to fix. (If you can do this, just email me the info.) Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 I get this error:[quote]Parse error: parse error, unexpected T_VARIABLE in C:\public_html\RPG\site.php on line 33[/quote]Line 33 being:[code] $now = strtotime("now");[/code]It's all running off a personal web server on my computer at the moment. Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 16, 2006 Share Posted September 16, 2006 Oops, go to line 32. It doesn't have a semicolon ending the line. Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 :( Still no luck with either of the two codes, just doesn't show anything. I will email you all the source code now.Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 16, 2006 Share Posted September 16, 2006 I'll be back in about an hour.I'm looking at your source code you sent me.BTW, are the lines 26-50 producing nothing? Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 Nothing is showing when i run it no.Thanks.Pete. Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 16, 2006 Share Posted September 16, 2006 I'm guessing there is a problem accessing the MySQL database properly (note that mysql queries are case-sensitive). The code below should let you know if any info is being passed through mysql_fetch_array. Just throw the code in somewhere in site.php.Are your other mysql fields showing up in the page? (such as $qry[name], $qry[editorrating], $qry[filesize], etc.)[code]$result = mysql_query("SELECT * FROM site WHERE id='$id'");$row = mysql_fetch_array($result) or die(mysql_error());echo "Date added: ".$row['dateadded'];[/code]The tutorial I'm looking at right now is [url=http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php]http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php[/url]. The main page is [url=http://www.tizag.com/mysqlTutorial/]http://www.tizag.com/mysqlTutorial/[/url].BTW, I'm curious, what server do you use on your home test server? I use the [url=http://aprelium.com/abyssws/]Abyss Web Server[/url]. Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 Yeah, other fields are showing. I put the dataadded query in and it displayed correctly 'Date added: 2006-09-16'.I'm using apache for my home test server.Pete. Quote Link to comment Share on other sites More sharing options...
markbett Posted September 16, 2006 Share Posted September 16, 2006 WOW you guys refuse to make it simple.... LOOKALL of these "time in the code below should be stringtotime() prior to running the code$time = time(); //this determines TODAYS DATE$time_diff = round(($POST_time - $time)/86400);//this will show how many days diffif(time_diff,=7){add image}; Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 How can i apply this to my system? Quote Link to comment Share on other sites More sharing options...
markbett Posted September 16, 2006 Share Posted September 16, 2006 change the post time variable to whatever bariable you are using the add your own code within the if statement...ohh theres a typo if(time_diff,=7){need to be if(time_diff<=7){ Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 Ok, so i have:[code]<?php$time = time(); //this determines TODAYS DATE$time_diff = round(('$qry[dateadded]' - $time)/86400);//this will show how many days diffif(time_diff<=7){"<img src='/images/new.gif'>"}; ?>[/code]Although i am getting this error:[quote]Parse error: parse error, unexpected '}' in C:\public_html\RPG\site.php on line 30[/quote]Line 30 being:[code]};[/code]Any ideas?Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
markbett Posted September 16, 2006 Share Posted September 16, 2006 if(time_diff<=7){ echo "<img src='/images/new.gif'>";} Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 I know get:[quote]Notice: Use of undefined constant time_diff - assumed 'time_diff' in C:\public_html\RPG\site.php on line 29[/quote]No image is shown either.Any ideas?Thanks. Quote Link to comment Share on other sites More sharing options...
markbett Posted September 16, 2006 Share Posted September 16, 2006 yes because you call time_diff on the fly... thats a notice not an errordid you stringtotime you date as i told you to.... you cannot compare 12-20-1987 to 12378175912 Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 [quote author=markbett link=topic=108166.msg435665#msg435665 date=1158433107]did you stringtotime you date as i told you to.... you cannot compare 12-20-1987 to 12378175912[/quote]If i knew how to do it... :P How/where do i do it?Pete. Quote Link to comment Share on other sites More sharing options...
markbett Posted September 16, 2006 Share Posted September 16, 2006 Peteyou will thank me... by the end of this you will understand how your code works and what does what.... while its frustrating now it will make you a better coder... now you have towo optionshttp://www.w3schools.com/php/func_date_strtotime.aspis the first... the other is when you do your SQL query you get the time AS UNIXTIME Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 I'm really not sure where i need to put the code or anything. Can you advise me please?Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 17, 2006 Author Share Posted September 17, 2006 Anyone? Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 18, 2006 Share Posted September 18, 2006 Got another test. Let's see if $x[dateadded] is even being passed into the while loop.At the beginning of your site.php (line 1), put this code in:[code]error_reporting(E_ALL);[/code]For the while loop, insert this code:[code]<?phpdate_default_timezone_set("US/Eastern");while ($x = mysql_fetch_assoc($result)) {print "<PRE>";if ($x[dateadded]) {print "dateadded exists\n";}if (!$x[dateadded]) {print "dateadded does <B>NOT</b> exist\n";}if (isset($x[dateadded])) {print "dateadded is set\n";}if (!isset($x[dateadded])) {print "dateadded is <B>NOT</B> set";}print "</PRE>";}?>[/code][b]Post any errors and any output from the while loop.[/b][b]Logic[/b]: If $x[dateadded] is not being passed into the while loop, then the snippet of code will never work. Let's see if that variable is being passed into the loop.You could also look to these pages for syntax [b]information [/b] --> [url=http://us2.php.net/mysql_fetch_array]http://us2.php.net/mysql_fetch_array[/url] and [url=http://us2.php.net/mysql_fetch_assoc]http://us2.php.net/mysql_fetch_assoc[/url]. They might help. 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.