Jump to content


Photo

New if within 7 days


  • Please log in to reply
56 replies to this topic

#41 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 16 September 2006 - 06:19 PM

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){


#42 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 16 September 2006 - 06:25 PM

Ok, so i have:

<?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'>"
};
   ?>

Although i am getting this error:

Parse error: parse error, unexpected '}' in C:\public_html\RPG\site.php on line 30


Line 30 being:
};

Any ideas?

Thanks.

Peter.


#43 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 16 September 2006 - 06:51 PM

if(time_diff<=7){ echo "<img src='/images/new.gif'>";
}

#44 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 16 September 2006 - 06:56 PM

I know get:

Notice: Use of undefined constant time_diff - assumed 'time_diff' in C:\public_html\RPG\site.php on line 29


No image is shown either.

Any ideas?

Thanks.

#45 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 16 September 2006 - 06:58 PM

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

#46 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 16 September 2006 - 07:03 PM

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


If i knew how to do it... :P How/where do i do it?

Pete.

#47 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 16 September 2006 - 07:07 PM

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...e_strtotime.asp

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

#48 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 16 September 2006 - 07:24 PM

I'm really not sure where i need to put the code or anything.  Can you advise me please?

Thanks.

Peter.

#49 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 17 September 2006 - 09:25 PM

Anyone?

#50 pkSML

pkSML
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationBucyrus, Ohio

Posted 18 September 2006 - 12:42 AM

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:
error_reporting(E_ALL);

For the while loop, insert this 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>";
}
?>

Post any errors and any output from the while loop.

Logic: 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 information --> http://us2.php.net/mysql_fetch_array and http://us2.php.net/mysql_fetch_assoc. They might help.
-Stephen

Need a LitlURL?

Got code to share? --> The Code-Bin

#51 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 18 September 2006 - 10:33 PM

Sorry about the late reply.

It doesn't show anything. No errors.  ???

Peter.

#52 pkSML

pkSML
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationBucyrus, Ohio

Posted 18 September 2006 - 10:43 PM

OK. Delete the while loop.

Put this code in its place:
print "<PRE>";
print_r($qry);
print "</PRE>";

Is there any output from the array? If so, what is it?
-----------------
BTW, what is this script used for? Is it a script that lists several entries or is it just supposed to list information about a single entry?
-Stephen

Need a LitlURL?

Got code to share? --> The Code-Bin

#53 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 19 September 2006 - 08:20 AM

The script lists information from one record (which is currently just rubbish typed in) but this is what the array said:

Array
(
    [0] => 9
    [id] => 9
    [1] => cx
    [name] => cx
    [2] => vcxvx
    [sitelink] => vcxvx
    [3] => xbv
    [sitedownload] => xbv
    [4] => 2006-09-13
    [dateadded] => 2006-09-13
    [5] => xbvb
    [publisher] => xbvb
    [6] => Pujhjdshfksjdhfjkhsdjkhfs
    [publisherinfo] => Pujhjdshfksjdhfjkhsdjkhfs
    [7] => 0
    [filesize] => 0
    [8] => bxcb
    [limitations] => bxcb
    [9] => vcxbvxv
    [requirements] => vcxbvxv
    [10] => 3D
    [graphics] => 3D
    [11] => bvxxcbvxbv
    [review] => bvxxcbvxbv
    [12] => vbbvxv
    [pros] => vbbvxv
    [13] => vcbxbvbvx
    [cons] => vcbxbvbvx
    [14] => 0
    [editorrating] => 0
    [15] =>
    [screenshot] =>
    [16] => 0
    [rating] => 0
    [17] => 0
    [num_votes] => 0
    [18] => 0
    [clicks] => 0
)



#54 pkSML

pkSML
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationBucyrus, Ohio

Posted 19 September 2006 - 11:43 PM

OK, great! I think the problem is solved.

Turns out you don't even need that while loop.

<?php
date_default_timezone_set("US/Eastern");

list($year, $mon, $day) = explode('-', $qry[dateadded]);

$sevenDays = (7 * 24 * 60 * 60); // 604,800 seconds in 7 days
$entryTime = strtotime("$year-$mon-$day");
$now = strtotime("now");

if (($now - $entryTime) < $sevenDays)
{
echo "<img src='/images/new.gif'>";
}
?>

What are the results of this code?
-Stephen

Need a LitlURL?

Got code to share? --> The Code-Bin

#55 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 20 September 2006 - 06:41 AM

:( Still doesn't show anything for some reason. I even tried changing the date so it's today, but still nothing. :(

Any other ideas?  ???

Thanks for all your help.

Peter.

#56 pkSML

pkSML
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationBucyrus, Ohio

Posted 20 September 2006 - 10:11 PM

<?php
date_default_timezone_set("US/Eastern");

list($year, $mon, $day) = explode('-', $qry[4]);

$sevenDays = (7 * 24 * 60 * 60); // 604,800 seconds in 7 days
$entryTime = strtotime("$year-$mon-$day");
$now = strtotime("now");

if (($now - $entryTime) < $sevenDays)
{
echo "<img src='/images/new.gif'>";
}
else
{
echo "<PRE>";
echo "This script is mind-boggling!";
echo '$qry[4] --> '.$qry[4]."\n";
echo '$now --> '.$now."\n";
echo '$entryTime --> '.$entryTime."\n";
echo '$sevenDays --> '.$sevenDays."\n";
echo '$year-\$mon-\$day --> '.$year."-".$mon."-".$day."\n";
echo "<PRE>";
}
?>

This script had better produce some output! That's why I added the else{} statement.

If things don't work right: Please post the output of this snippet. Also email or post your source for site.php. I'll look for any syntax errors.
-Stephen

Need a LitlURL?

Got code to share? --> The Code-Bin

#57 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 20 September 2006 - 10:18 PM

This has got to be the worst php problem i have come across in my 2 weeks of learning :P

The script shows nothing.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users