Jump to content

Archived

This topic is now archived and is closed to further replies.

wwfc_barmy_army

New if within 7 days

Recommended Posts

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 pkSML

Thanks.

Peter.

**Edit** line 30 is:
[code]if (strtotime("$x['dateadded']") > $sevenDays) {[/code]

Share this post


Link to post
Share on other sites
What's on line 30 of site.php?

BTW, we both moved from nOObie to non-spammers on this forum  ;D

*Edit
I 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?

Share this post


Link to post
Share on other sites
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]<?php
date_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]<?php
date_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]

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Oops, go to line 32. It doesn't have a semicolon ending the line.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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].

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
WOW you guys refuse to make it simple.... LOOK

ALL 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 diff
if(time_diff,=7){
add image};

Share this post


Link to post
Share on other sites
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){

Share this post


Link to post
Share on other sites
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 diff
if(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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
yes because you call time_diff on the fly... thats a notice not an error

did you stringtotime you date as i told you to....  you cannot compare 12-20-1987 to 12378175912

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
Pete
you 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 options

http://www.w3schools.com/php/func_date_strtotime.asp

is the first... the other is when you do your SQL query you get the time AS UNIXTIME

Share this post


Link to post
Share on other sites
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]
<?php
date_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.

Share this post


Link to post
Share on other sites

×

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.