Jump to content

New if within 7 days


wwfc_barmy_army

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

  • Replies 56
  • Created
  • Last Reply

Top Posters In This Topic

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?
Link to comment
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]
Link to comment
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.)
Link to comment
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].
Link to comment
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};
Link to comment
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.
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

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.