
pkSML
Members-
Posts
191 -
Joined
-
Last visited
Everything posted by pkSML
-
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?
-
Oops, go to line 32. It doesn't have a semicolon ending the line.
-
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.)
-
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]
-
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?
-
For diagnostic's sake, give me the output of this code. It just lists the variables and their values. [code]<?php date_default_timezone_set("US/Eastern"); $sevenDays = strtotime('today -7 days'); while ($x = mysql_fetch_array($result)) { list($year, $mon, $day) = explode('-', $x['dateadded']); if (strtotime("$year-$mon-$day") > $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]
-
Is the dateadded field separated with dashes or slashes? What error message did you get previously?
-
OK, that makes a huge difference and explains why it wasn't working right. [code]<?php date_default_timezone_set("US/Eastern"); $sevenDays = strtotime('today -7 days'); while ($x = mysql_fetch_array($result)) { list($year, $mon, $day) = explode('-', $x['dateadded']); if (strtotime("$year-$mon-$day") > $sevenDays) { // show your image here since it's new! echo "<img src='/images/new.gif'>"; } } ?>[/code] BTW, the variables $year, $mon, and $day come from $x['dateadded']. The line that begins with list() basically splits the string at every dash mark (using the explode function), and assigns the variables in the order of the list. You might even be able to use more concise code: [code]<?php date_default_timezone_set("US/Eastern"); $sevenDays = strtotime('today -7 days'); while ($x = mysql_fetch_array($result)) { if (strtotime("$x['dateadded']") > $sevenDays) { // show your image here since it's new! echo "<img src='/images/new.gif'>"; } } ?>[/code] Do either of these work?
-
OK, let's try fixing the original code (hope you don't mind :)). The problem was occurring with the timezone function. Let's set the timezone. [code]<?php date_default_timezone_set("US/Eastern"); $sevenDays = strtotime('today -7 days'); while ($x = mysql_fetch_array($result)) { list($mon, $day, $year) = explode('-', $x['dateadded']); if (strtotime("$year-$mon-$day") > $sevenDays) { // show your image here since it's new! echo "<img src='/images/new.gif'>"; } } ?>[/code] My timezone is Eastern, but you can find your timezone at [url=http://us2.php.net/manual/en/timezones.america.php]http://us2.php.net/manual/en/timezones.america.php[/url] if you live in America. Otherwise, find it at [url=http://us2.php.net/manual/en/timezones.php]http://us2.php.net/manual/en/timezones.php[/url]. [b]Edit:[/b] About the previous posts, markbett is right: strtotime is better to use than day of year. The only problem that occurs with day of year is when it's time to change years (you'd not see the new graphic for the first seven days of a new year).
-
wwfc_barmy_army, could you provide an example record of $mon, $day, $year? What I'm thinking: Maybe SQL returns $year as 06 instead of 2006. This would cause the script to never show the NEW graphic. If this is the case, just change the line [b]$thisyear = date("Y");[/b] to [b]$thisyear = date("y");[/b] (just change capital Y to little y).
-
If you want to put that header on your images, you can do it one of two ways. 1. Via the server - have all the images in a certain folder and set the custom header to apply to all requests from that folder. This is the tricky way, as you must change the configuration for your server, if this is even allowed. 2. Via PHP - you can serve images from a php script. This is very simple. (The sig you see below is displayed with a PHP script.) HTML code: [code]<img src="image1.php">[/code] PHP code (image1.php): [code]<?php header('Content-type: image/gif'); //MIME type for file header('Cache-Control: no-cache'); //file not stored in browser cache $handle = file_get_contents("image.gif"); //file to print print "$handle"; fclose($handle); ?>[/code] *Edit: I forgot to add the cache-control header in the PHP code. It's there now.
-
I believe you can get around the browser caching problem with custom HTTP headers. Note my sig picture you see below for instance. My [url=http://calvarybucyrus.org/server/server.htm]server - my home computer :)[/url] sent your browser the header: [b]Cache-Control: no-cache[/b]. The browser shouldn't save the picture at all. Note: There's always an exception, so here it is. A program like [url=http://stephen.calvarybucyrus.org/redirect.php?file=WinGet]WinGet[/url] will download the file, regardless of the headers.
-
If you'd like to display MM-DD-YYYY at HH:MM:SS, try this code: [code] <?php echo date("m-d-Y \a\\t H:i:s",$rs_mem[$i][date_added]); ?> code][/code]
-
This code is fixed. I hope the syntax is proper. date(z) does not need to take into account the month because it just returns the day of year. This updated code makes sure that the year is the same. [code]<?php while ($x = mysql_fetch_array($result)) { list($mon, $day, $year) = explode('-', $x['dateadded']); $day = date('z', mktime(0, 0, 0, $mon, $day, $year)) + 1; // day of year for datestamp $thisyear = date("Y"); $today = date("z") + 1; // today's day of year if ((($today - $day) < 7) && ($year == $thisyear)) { // show your image here since it's new! echo "<img src='/images/new.gif'>"; } } ?>[/code]
-
Try this. [code]<?php while ($x = mysql_fetch_array($result)) { list($mon, $day, $year) = explode('-', $x['dateadded']); $day = date('z', mktime(0, 0, 0, $mon, $day, $year)) + 1; // day of year for datestamp $today = date("z") + 1; // today's day of year if (($today - $day) < 7) { // show your image here since it's new! echo "<img src='/images/new.gif'>"; } } ?>[/code]
-
Hmmm... Very interesting problem. I tried this on my webserver and have no problems with the br tags. The textarea on the second page looks perfect. The simple code I used was [code]<textarea rows=20 cols=60> <?php echo $_POST['code']; ?> </textarea>[/code] Note that I am using WinXP. It might make a difference if your server is using *nix. Here is a test to see where the problem lies. Save the contents of the posted data to a file. Examine the file for the annoying br tags. If they are not there, PHP seems to be the culprit. I'd take a close look at the php.ini file. If all fails, save the posted data to a file, then retrieve the file to display in the textarea on the second page. It's odd, but it may work!